i f i have an array a=[1 2 3 4 1;6 7 8 9 2].I need to split this array based on the value in last column.Resultant array b=[1 2 3 4],c=[6 7 8 9]. The splitted array b should contain the row whose last column is 1 and c 2
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
a=[1 2 3 4 1 5 6 7 8 2 3 4 5 6 1 4 3 2 1 1] Resultant matrix is : b=[1 2 3 4 3 4 5 6 4 3 2 1] c=[5 6 7 8]
0 Kommentare
Antworten (1)
Julia
am 28 Okt. 2014
Bearbeitet: Julia
am 28 Okt. 2014
Hi,
here is a solution for your small problem. If a is larger, you can use a loop.
b=[];
c=[];
if a(1,end)==1
b=[b,a(1,1:end-1)];
end
if a(2,end)==2
c=[c,a(2,1:end-1)];
end
Or with switch-case. Something like:
switch a(i,end) % where i is a counting index of a loop
case 1
b=[b,a(i,1:end-1)];
case 2
c=[c,a(i,1:end-1)];
end
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!