How to sort an array and divide it to n parts depending of the values in it
2 views (last 30 days)
Show older comments
Hi everybody, First of all , I would like to thank in advance the help.
I have a problem, the first one it is that I am bennigner in matlab and I do not know probably If my explanation is good.
I have the following file:
I know how to open, and manage with it. what I would like to know is as you see, there are 4 columms, each columm has 3 groups of values from min to max I want to make some loop to crop the matrix and divide in 3 diferent matrix that have only one group from min to max, for example,
1 1
2 2
3 3
1 1
2 2
3 3
1 1
2 2
3 3
and obtain 3 diferent matrix like below:
1 1
2 2
3 3
the purpose of using a loop is because the file size changes in rows and columns.
Any help is deeply valuable for me.
Heartfelt thanks,
Miguel
0 Comments
Answers (1)
Andrei Bobrov
on 3 Sep 2013
Edited: Andrei Bobrov
on 3 Sep 2013
m = dlmread('pathtovalidx.txt');
idx = cumsum([true;diff(m(:,1)) < 0]);
a = unique(histc(idx,1:idx(end)));
if numel(a) == 1
out = reshape(m,a,size(m,2),[]);
else
out = mat2cell(m,a,size(m,2));
end
here out is three dimension double array or cell array, where each page or cell with your new matrix
0 Comments
See Also
Categories
Find more on Creating and Concatenating Matrices 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!