필터 지우기
필터 지우기

How can i seperate columns by comparing the values of first row?

조회 수: 1 (최근 30일)
suchismita
suchismita 2016년 5월 18일
답변: ahsan mahmood 2016년 5월 18일
I have a martix
A= 0 1 0 0 1 1 1 1 1 1
0 1 0 0 1 1 1 1 1 1
0 1 0 0 1 0 1 1 1 1
0 1 0 0 1 1 1 1 1 0
1 1 0 0 1 1 1 0 1 1
0 1 0 0 1 1 1 0 1 1
0 1 0 0 1 1 0 1 1 1
0 1 0 0 1 1 1 1 0 0
0 1 0 0 1 1 1 1 1 1
0 0 0 0 1 1 1 1 1 0
0 1 0 0 1 1 1 1 1 1
where, in compare to first row i want to have two separate matrix as B with all values which will have A(1,:)==0 and C with all values which will A(1,:)==1
In other words,from this example i want to separate 1st, 3rd and 4th column in a separate matrix and others in another matrix.

채택된 답변

Andrei Bobrov
Andrei Bobrov 2016년 5월 18일
t = A(:,1) == 0;
B = A(:,t)
C = A(:,~t)

추가 답변 (1개)

ahsan mahmood
ahsan mahmood 2016년 5월 18일
clc;
clear all;
A=[1 1 0;1 2 5;3 6 8;5 4 2];
j=1;
k=1;
nn=size(A);
for i=1:nn(2)
if A(1,i)==1
C(:,j)=A(2:end,i);
j=j+1;
else
B(:,k)=A(2:end,i);
k=k+1;
end
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