How to sort an array and divide it to n parts depending of the values in it

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

답변 (1개)

Andrei Bobrov
Andrei Bobrov 2013년 9월 3일
편집: Andrei Bobrov 2013년 9월 3일
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

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2013년 9월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by