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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:20:27+00:00 2026-05-23T14:20:27+00:00

I need to sort out few small matrices from 1 huge raw matrix …according

  • 0

I need to sort out few small matrices from 1 huge raw matrix …according to sorting 1st column (1st column contain either 1, 2, or 3)…

if 1st column is 1, then randomly 75% of the 1 save in file A1, 25% of the 1 save in file A2.

if 1st column is 2, then randomly 75% of the 2 save in file B1, 25% of the 2 save in file B2.

if 1st column is 3, then randomly 75% of the 3 save in file C1, 25% of the 3 save in file C2.

how am i going to write the code?

Example:

a raw matrix has 15 rows x 6 columns:

7 rows are 1 in 1st column, 5 rows are 2 in 1st column, and 3 rows are 3 in 1st column.

1   -0.05   -0.01   0.03    0.07    0.11

1   -0.4    -0.36   -0.32   -0.28   -0.24

1   0.3 0.34    0.38    0.42    0.46

1   0.75    0.79    0.83    0.87    0.91

1   0.45    0.49    0.53    0.57    0.61

1   0.8 0.84    0.88    0.92    0.96

1   0.05    0.09    0.13    0.17    0.21

2   0.5 0.54    0.58    0.62    0.66

2   0.4 0.44    0.48    0.52    0.56

2   0.9 0.94    0.98    1.02    1.06

2   0.85    0.89    0.93    0.97    1.01

2   0.75    0.79    0.83    0.87    0.91

3   0.36    0.4 0.44    0.48    0.52

3   0.6 0.64    0.68    0.72    0.76

3   0.4 0.44    0.48    0.52    0.56

7 rows got 1 in 1st column, randomly take out 75% of 7 rows (which is 7*0.75=5.25) to be new matrix (5rows x 6 columns), the rest of 25% become another new matrix

5 rows got 2 in 1st column, randomly take out 75% of 5 rows (which is 5*0.75=3.75) to be new matrix (4rows x 6 columns), the rest of 25% become another new matrix

3 rows got 3 in 1st column, randomly take out 75% of 3 rows (which is 3*0.75=2.25) to be new matrix (2rows x 6 columns), the rest of 25% become another new matrix

Result:

A1=

1   -0.4    -0.36   -0.32   -0.28   -0.24

1   0.3 0.34    0.38    0.42    0.46

1   0.75    0.79    0.83    0.87    0.91

1   0.8 0.84    0.88    0.92    0.96

1   -0.05   -0.01   0.03    0.07    0.11

B1=

2   0.9 0.94    0.98    1.02    1.06

2   0.85    0.89    0.93    0.97    1.01

2   0.5 0.54    0.58    0.62    0.66

2   0.75    0.79    0.83    0.87    0.91

C1=

3   0.36    0.4 0.44    0.48    0.52

3   0.4 0.44    0.48    0.52    0.56
  • 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-05-23T14:20:28+00:00Added an answer on May 23, 2026 at 2:20 pm

    here is one possible solution to your problem using the function randperm:

    % Create matrices
    firstcol=ones(15,1);
    firstcol(8:12)=2;
    firstcol(13:15)=3;
    mat=[firstcol rand(15,5)];
    % Sort according to first column
    A=mat(mat(:,1)==1,:);
    B=mat(mat(:,1)==2,:);
    C=mat(mat(:,1)==3,:);
    % Randomly rearrange lines
    A=A(randperm(size(A,1)),:);
    B=B(randperm(size(B,1)),:);
    C=C(randperm(size(C,1)),:);
    % Select first 75% lines (rounding)
    A1=A(1:round(0.75*size(A,1)),:);
    A2=A(round(0.75*size(A,1))+1:end,:);
    B1=B(1:round(0.75*size(B,1)),:);
    B1=B(round(0.75*size(B,1))+1:end,:);
    C1=C(1:round(0.75*size(C,1)),:);
    C1=C(round(0.75*size(C,1))+1:end,:);
    

    Hope it helps.

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

Sidebar

Related Questions

I need to sort tuples according to the second element of each tuple but
How do you sort out the good buzz from the bad buzz? - I
There are a few ways to do a merge sort, but I specifically need
Well, I asked a question about sorting few days ago. I found out how
I need some sort of interactive chart control for my .NET-based web app. I
I need some sort of node-graph editor, that hopefully works on both Mac and
I need to sort on a date-field type, which name is mod_date. It works
I need to sort close to a 1,00,000 floating point entries in Delphi. I
I need to sort string, and I came up with the following function. def
I need to sort an array that can look like this: $array[4][0] = array('id'

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.