Borrar filtros
Borrar filtros

how do you eliminate rows of a matrix?

3 visualizaciones (últimos 30 días)
Highwayman2
Highwayman2 el 1 de Mayo de 2015
Respondida: Star Strider el 1 de Mayo de 2015
I have a 100x2 matrix of random values and i need to remove any row that has a negative value in it. I originally changed all the positive values to 1 and negative values to 0 by setting the matrix to be > 0, just a bit lost on how to delete the rows with a zero (negative value).
Thanks in advance

Respuestas (2)

the cyclist
the cyclist el 1 de Mayo de 2015
% Some pretend data
A = rand(100,2);
% Identify row with negative values
idx = any(A<0,2);
% Remove them
A(idx,:) = [];

Star Strider
Star Strider el 1 de Mayo de 2015
One possibility:
d = randi(50, 100, 2)-10; % Original Random Matrix
ds = d; % Check Original Matrix
d(any(d<0,2),:) = []; % Rmeove Negative Element Rows
The ‘ds’ assignment preserves ‘d’ so you can check to see that the routine works. It is not necessary for the code.

Categorías

Más información sobre Creating and Concatenating Matrices 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