Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8854851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:58:46+00:00 2026-06-14T13:58:46+00:00

I am working on implementing cross validation at Matlab without using any other functions

  • 0

I am working on implementing cross validation at Matlab without using any other functions except for native ones.

I have a matrix like that:

1
2
3
..
N

I have a fold size M

At first iteration I want to take that:

1
2
3
..
N-M

at second iteration:

1
2
3
..
.. //Number o f M elements didn't included here
N-M+1
N-M+2
..
N

iterate until I process

M+1
M+2
..
N

When I don’t include any set of elements I want to assign them into another variable or I want to know indexes so I can process them (this one is better for performance)

Further information about cross validation: http://en.wikipedia.org/wiki/Cross-validation_(statistics)

This graphic explains what I want(form Georgia Tech University slides):
enter image description here

I am new to matlab, how can I implement it easily?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:58:47+00:00Added an answer on June 14, 2026 at 1:58 pm

    The following bit of code will segment your data as illustrated in your graphic.

    K = 5; %Fold size
    N = 25; % Number of data points
    
    data = rand(1,N); % Some fake data
    
    testIdxs = reshape(1:N,K, N/k)'; %now each row has the indices for one test set
    
    % All indices that aren't in the test, should belong to the training set. 
    trainIdx = zeros(K, N-K);
    for ix = 1:N/k
        temp                = 1:25;
        temp(testIdxs(ix,:)) = [];
        trainIdx(ix,:)      = temp;
    end
    

    Keep in mind that this method only works if N is a multiple of K.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working on implementing the first 6 functions of the NSComparisonMethods protocol
I'm working on implementing a cache for a lot of bitmap tiles I have.
I'm working on implementing a single pass depth-peeling algorithm by using atomic textures in
I'm working on implementing deferred shading to my game. I have rendered the diffuse
I am currently working on implementing puppet in our environment, however, I have a
I am working on implementing tabs for my application. Everything is working well except
I have been working on implementing the Ancestry gem in my rails app, I
I have been working on implementing a (1) server, (n) worker role servers setup
I'm working on implementing an Octave interpreter inside of an FastCGI session using C/C++
i am working on implementing list view, i have user BaseAdapter class.i am trying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.