Extract rows that their columns have specific values
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hi,
I have the following matrix:
A = [ 0.1 0 ;
0.5 0 ;
3 0 ;
0 0 ]
and I want to extract the rows that their columns elements are larger or equal to zero and less or equal to one:
for i = 1:size(A,1)
ind = (A(i,:) >=0) & (A(i,:) <=1);
A1 = A(ind,:)
end
The answer should be:
A1 = [0.1 0 ;
0.5 0 ;
0 0 ]
but my code does not give me the last row.
Any help would be appreicted.
0 comentarios
Respuestas (2)
KSSV
el 12 de Oct. de 2022
A = [ 0.1 0 ;
0.5 0 ;
3 0 ;
0 0 ] ;
for i = 1:size(A,1)
ind = (A(i,:) >=0) & (A(i,:) <=1);
A1 = A(i,ind)
end
0 comentarios
VBBV
el 6 de Nov. de 2022
A = [ 0.1 0 ;
0.5 0 ;
3 0 ;
0 0 ];
for i = 1:size(A,1)
if (A(i,:) >= 0) & (A(i,:) <=1) %
A1(i,:) = A(i,:);
end
end
A1
0 comentarios
Ver también
Categorías
Más información sobre MATLAB Coder 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!