create sub arrays from a array
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello Everyone,
I am new to MATLAB so I am asking a very basic question which I am not able to solve.
I have an array of diemensions 672*9 , I want to create smaller arrays by comapring the value of column 9 only.
So for example my values in column 9 are
4
4
4
3.5
3
3.1
3.2
4
3.5
I specify the threshold value as 3.4 . So as my values in first 4 rows is more than 3.4 I store them in a new array. Then next 3 values in second array and finally last 2 values in third array.
I hope I have framed the question properly.
0 Kommentare
Akzeptierte Antwort
Azzi Abdelmalek
am 5 Jun. 2013
Bearbeitet: Azzi Abdelmalek
am 5 Jun. 2013
Edit
a=[4,4,4,3.5,3,3.1,3.2,4,3.5];
idx=a>=3.4;
idx2=sort([strfind(idx,[true false]) strfind(idx,[false,true]) numel(a)]);
idx1=[1 idx2(1:end-1)+1];
% pre-allocate;
y=cell(1,numel(idx));
for k=1:numel(idx1)
y{k}=a(idx1(k):idx2(k));
end
y{1}
y{2}
y{3}
6 Kommentare
Jan
am 5 Jun. 2013
@Ricky: I do not understand your explanations. Does the method shown by Azzi help to solve your problem?
Weitere Antworten (1)
Andrei Bobrov
am 6 Jun. 2013
a=[4,4,4,3.5,3,3.1,3.2,4,3.5];
out = accumarray(cumsum([true; diff(a(:) > 3.4)~=0]),a(:),[],@(x){x});
0 Kommentare
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!