필터 지우기
필터 지우기

create binary 0 and 1

조회 수: 3 (최근 30일)
Quynh tran
Quynh tran 2017년 5월 19일
편집: James Tursa 2017년 5월 19일
Dear all,
I have matrix of binary with n=5
A=[0 0 0 0 1
0 0 0 1 0
0 0 1 0 0
....
1 1 1 1 1]
but I only want to take a submatrix with 3 number 1 inside
subA=[ 0 1 1 0 1
1 0 1 0 1
0 1 1 1 0
........]
and
subB=[0 0 0 0 1
0 0 0 1 0
0 0 1 0 0
0 1 0 0 0
1 0 0 0 0
0 0 0 1 1
.....
0 1 1 0 1
1 0 1 0 1
0 1 1 1 0
........]
. Couyld you help me? Thanks

채택된 답변

James Tursa
James Tursa 2017년 5월 19일
편집: James Tursa 2017년 5월 19일
subA = A(sum(A,2)==3,:);
For subB it is not entirely clear to me what you want. Do you want the rows of A arranged so that all rows with one 1 come first, then all rows with two 1's, then all rows with three 1's? Or what? E.g., this?
subB = [A(sum(A,2)==1,:);...
A(sum(A,2)==2,:);...
A(sum(A,2)==3,:);...
A(sum(A,2)==4,:);...
A(sum(A,2)==5,:)];
  댓글 수: 2
Quynh tran
Quynh tran 2017년 5월 19일
in subB, I want with 5 colums but number of 1 in a row is less than 3
James Tursa
James Tursa 2017년 5월 19일
편집: James Tursa 2017년 5월 19일
Your words do not match your example. Maybe a truncated version of the above?
subB = [A(sum(A,2)==1,:);...
A(sum(A,2)==2,:);...
A(sum(A,2)==3,:)];
or
subB = [A(sum(A,2)==1,:);...
A(sum(A,2)==2,:)];

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Types에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by