Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
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 comentarios
Firas Al-Kharabsheh
Firas Al-Kharabsheh el 15 de Abr. de 2016
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 ]

Iniciar sesión para comentar.

Respuestas (1)

Azzi Abdelmalek
Azzi Abdelmalek el 15 de Abr. de 2016
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,:)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by