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 8592219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:42:13+00:00 2026-06-11T23:42:13+00:00

I have a matrix (I guess in MatLab you call it a struct) or

  • 0

I have a matrix (I guess in MatLab you call it a struct) or data structure:

  data: [150x4 double]
labels: [150x1 double]

here is out my matrix.data looks like assume I do load my file with the name of matrix:

5.1000    3.5000    1.4000    0.2000
4.9000    3.0000    1.4000    0.2000
4.7000    3.2000    1.3000    0.2000
4.6000    3.1000    1.5000    0.2000
5.0000    3.6000    1.4000    0.2000
5.4000    3.9000    1.7000    0.4000
4.6000    3.4000    1.4000    0.3000
5.0000    3.4000    1.5000    0.2000
4.4000    2.9000    1.4000    0.2000
4.9000    3.1000    1.5000    0.1000
5.4000    3.7000    1.5000    0.2000
4.8000    3.4000    1.6000    0.2000
4.8000    3.0000    1.4000    0.1000
4.3000    3.0000    1.1000    0.1000
5.8000    4.0000    1.2000    0.2000
5.7000    4.4000    1.5000    0.4000
5.4000    3.9000    1.3000    0.4000
5.1000    3.5000    1.4000    0.3000
5.7000    3.8000    1.7000    0.3000
5.1000    3.8000    1.5000    0.3000

And here is my matrix.labels look like

 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1

I am trying to create 10 cross fold validation without using any of the existing functions in MatLab and due to my very limited MatLab knowledge I am having trouble going forward with from what I have. Any help would be great.

This is what I have so far, and I am sure this probably not the matlab way, but I am very new to matlab.

function[output] = fisher(dataFile, number_of_folds)
    data = load(dataFile);
    %create random permutation indx
    idx = randperm(150);
    output = data.data(idx(1:15),:);
end
  • 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-11T23:42:14+00:00Added an answer on June 11, 2026 at 11:42 pm

    Here is my take for this cross validation. I create dummy data using magic(10) also I create labels randomly. Idea is following , we get our data and labels and combine them with random column. Consider following dummy code.

    >> data = magic(4)
    
    data =
    
        16     2     3    13
         5    11    10     8
         9     7     6    12
         4    14    15     1
    
    >> dataRowNumber = size(data,1)
    
    dataRowNumber =
    
         4
    
    >> randomColumn = rand(dataRowNumber,1)
    
    randomColumn =
    
        0.8147
        0.9058
        0.1270
        0.9134
    
    
    >> X = [ randomColumn data]
    
    X =
    
        0.8147   16.0000    2.0000    3.0000   13.0000
        0.9058    5.0000   11.0000   10.0000    8.0000
        0.1270    9.0000    7.0000    6.0000   12.0000
        0.9134    4.0000   14.0000   15.0000    1.0000
    

    If we sort X according column 1, we sort our data randomly. This will give us cross validation randomness. Then next thing is to divide X according to cross validation percentage. Accomplishing this for one case easy enough. Lets consider %75 percent is train case and %25 percent is test case. Our size here is 4, then 3/4 = %75 and 1/4 is %25.

    testDataset = X(1,:)
    trainDataset = X(2:4,:)
    

    But accomplishing this a bit harder for N cross folds. Since we need to make this N times. For loop is necessary for this. For 5 cross folds. I get , in first f

    1. 1st fold : 1 2 for test, 3:10 for train
    2. 2nd fold : 3 4 for test, 1 2 5:10 for train
    3. 3rd fold : 5 6 for test, 1:4 7:10 for train
    4. 4th fold : 7 8 for test, 1:6 9:10 for train
    5. 5th fold : 9 10 for test, 1:8 for train

    Following code is an example for this process:

    data = magic(10);
    dataRowNumber = size(data,1);
    labels= rand(dataRowNumber,1) > 0.5;
    randomColumn = rand(dataRowNumber,1);
    
    X = [ randomColumn data labels];
    
    
    SortedData = sort(X,1);
    
    crossValidationFolds = 5;
    numberOfRowsPerFold = dataRowNumber / crossValidationFolds;
    
    crossValidationTrainData = [];
    crossValidationTestData = [];
    for startOfRow = 1:numberOfRowsPerFold:dataRowNumber
        testRows = startOfRow:startOfRow+numberOfRowsPerFold-1;
        if (startOfRow == 1)
            trainRows = [max(testRows)+1:dataRowNumber];
            else
            trainRows = [1:startOfRow-1 max(testRows)+1:dataRowNumber];
        end
        crossValidationTrainData = [crossValidationTrainData ; SortedData(trainRows ,:)];
        crossValidationTestData = [crossValidationTestData ;SortedData(testRows ,:)];
    
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have matrix (a) with (1:10),<10 x 1> double. I would like to copy
I have a matrix of data (the columns represent time, and the rows spectrum
I have a matrix A which I want to convert into a data.frame of
I have a matrix of objects that contains data in this form: name A,2,name
I have a matrix in MATLAB and I need to find the 99% value
I have a std::istream which refers to matrix data, something like: 0.0 1.0 2.0
I have a 161X911 data matrix of 0,1,2's and then there are some NaN's
If I have a M by N matrix filled with data, what is the
I'm working with R. I have a matrix structure but stored in three lists
Have a matrix report now that has Position, Hours and Wages for a location

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.