필터 지우기
필터 지우기

if i have a matrix and i want check condition if true then copy this row or column to new matrix?

조회 수: 1 (최근 30일)
if i have a (n,m) matrix A and i want to check condition if true then copy this row or column to new matrix?
A = [ 1 1 1 0 0 0 0 0 1 1
1 1 0 0 0 0 0 1 0 1
1 1 0 0 0 0 0 1 0 1
1 1 0 0 0 0 0 0 0 1
1 1 1 0 0 0 0 0 1 1
1 1 1 1 0 0 0 1 1 1
1 1 1 1 1 0 1 1 1 1 ]
the condition is if there a row or a column
* if the row or the column have a group of one with one zero between them
* if the number of zero in this row or column < number of ones in this row
if this two condition true then copy this row or column to new zeros matrix
  댓글 수: 2
Firas Al-Kharabsheh
Firas Al-Kharabsheh 2016년 4월 15일
s_zeros = [ 1 1 0 0 0 0 0 0 0 1
1 1 0 0 0 0 0 0 0 1
1 1 0 0 0 0 0 0 0 1
1 1 0 0 0 0 0 0 0 1
1 1 0 0 0 0 0 0 0 1
1 1 0 0 0 0 0 0 0 1
1 1 1 1 1 0 1 1 1 1 ]

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

답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2016년 4월 15일
A = [ 1 1 1 0 0 0 0 0 1 1
1 1 0 0 0 0 0 1 0 1
1 1 0 0 0 0 0 1 0 1
1 1 0 0 0 0 0 0 0 1
1 1 1 0 0 0 0 0 1 1
1 1 1 1 0 0 0 1 1 1
1 1 1 1 1 0 1 1 1 1 ]
[n,m]=size(A)
s=sum(A,2)
for k=1:n
idx(k,1)=~isempty(strfind(A(k,:),[1 0 1]))
end
ii=s>m/2 & idx
out=A(ii,:)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by