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
2 次查看(过去 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]
0 个评论
回答(1 个)
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!