Assign new matrices for a certain condition, in Matlab

2 views (last 30 days)
I have a matrix,DataFile=98854x66. One of those columns("coarse event") can only be 0 or a 1. It will be 0 for a non-stable condition and 1 for a stable condition.
I am able to extract one whole matrix for all 66 columns for which the "coarse event" is 1. This is done by a function("extractor") that was written:
%(Matrix to extract from,coarse event column,lower value,upper value)
A = extractor(DataFile,59,1,1);
For example, if I had a coarse event=0 for 4000 rows, then coarse event=1 for 8000 rows, then coarse event=0 for 3000 rows, then coarse event=1 for 7000 rows,finally all remaining rows has a coarse event=0. This then leaves me with A=15000x66 matrix. What I would like to have a two matrices one 8000x66 and one 7000x66.
In reality I would like have the a n-amount of matrices, for which the "coarse event" is 1. I know it must be any simple combination of using if, for, or while statements, all of which has failed in my attempts in my limited experience in Matlab. Thank you for the help!

Answers (1)

Image Analyst
Image Analyst on 11 Jul 2017
I don't know what that function does but you can use simple indexing to extract the rows you want. First get the "coarse event" column:
coarseEventColumn = DataFile(:, 15); % Change 15 to whatever column it's in.
% Now find out where that column is 1:
coarseEvent1Rows = coarseEventColumn == 1;
% Extract only those rows from the full data:
dataIs1 = DataFile(coarseEvent1Rows, :);
% Now do the same thing for where the coarse events are 0:
% Now find out where that column is 0:
coarseEvent0Rows = coarseEventColumn == 0;
% Extract only those rows from the full data:
dataIs0 = DataFile(coarseEvent0Rows, :);
  2 Comments
Gustav Potgieter
Gustav Potgieter on 12 Jul 2017
100%. This separates all the 1's and 0's into two matrices. Your code is shorter and more effective than the function that I was using, but it does accomplish the same thing as just mentioned.
What I am wondering, how can I achieve n-amount of matrices(dataIs1(1),dataIs1(2),...,dataIs1(n)) , for which the "coarse event" is 1?
Image Analyst
Image Analyst on 12 Jul 2017
Just do it over and over again every time you get change "DataFile". If, for some weird reason, you need to store them all in memory at the very same time then you'd have to put the various dataIs1 and dataIs0 variables into a cell array, like 2 cells for each data file you read in.

Sign in to comment.

Categories

Find more on Tables in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!