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]

답변 (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 CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by