Borrar filtros
Borrar filtros

how to delete columns from matrix

2 visualizaciones (últimos 30 días)
kmla
kmla el 3 de Mzo. de 2018
Comentada: kmla el 3 de Mzo. de 2018
i have matrix (2,n) i want to delete the columns that contain a value < 20 from the two rows for exmple: a=[3 4 7 20 35 40; 29 70 5 90 45 2] the output a=[20 35; 90 45] i tried this code but not work correctly
if true
% code
end
a=[3 4 7 20 35 40; 29 70 5 90 45 2]
for i=1:size(a,1)
for j=1:size(a,2)
if (a(i)<20)
a(:,i)=[];
end
end
end

Respuesta aceptada

David Fletcher
David Fletcher el 3 de Mzo. de 2018
a(:,all(a>=20))
  1 comentario
kmla
kmla el 3 de Mzo. de 2018
thank you sir, this also work
for i= size(a, 2):-1:1
a(:, a(1, :) < 20) = []
a(:, a(2, :) < 20) = []
end

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Multidimensional Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by