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

1 回表示 (過去 30 日間)
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]

回答 (1 件)

Julia
Julia 2014 年 10 月 28 日
編集済み: Julia 2014 年 10 月 28 日
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

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by