Delete row from Matrix

366 visualizaciones (últimos 30 días)
Nancy
Nancy el 21 de Jun. de 2012
Comentada: muhammad usama el 7 de Mayo de 2023
I have a Matrix of 400 rows and 40 columns. I want to completely remove rows 3 and 9 to get a matrix with 398 rows. How can I do it in MATLAB.
  3 comentarios
Yuvraj Praveen Soni
Yuvraj Praveen Soni el 9 de Dic. de 2019
if assume A is your matrix with 400 rows and 40 column,
To remove 3rd row
a(3,:)=[];
now your 9th row become 8th row;
a(8,:)=[];
and with this your 3rd and 9th row will be deleted, you can also check the size by
size(a);
Thank You
Gokul Krishna N
Gokul Krishna N el 2 de Nov. de 2020
Thanks

Iniciar sesión para comentar.

Respuesta aceptada

Jan
Jan el 22 de Jun. de 2012
Editada: MathWorks Support Team el 9 de Nov. de 2018
If you have a matrix A and want to delete the 3rd and 9th rows, you can use the command:
A([3,9],:) = [];
  5 comentarios
Walter Roberson
Walter Roberson el 18 de Jun. de 2019
Katarina, I am not clear as to where you are seeing anything about deleting columns in this Answer?
If you want to delete a column then name it in the second index:
A(:,k) = [];
Arezoo Samiei
Arezoo Samiei el 7 de Oct. de 2021
Thank you so much Jan!

Iniciar sesión para comentar.

Más respuestas (6)

Peter
Peter el 30 de Nov. de 2012
"I have a Matrix of 400 rows and 40 columns.I want to completely remove rows 3 and 9 to get a matrix with 398 rows. How can I do it in MATLAB."
Matrix_2 = Matrix_1( [1:2,4:8,10:end] , : )
Best,
Pete
  1 comentario
muhammad usama
muhammad usama el 7 de Mayo de 2023
Thank you, the simplest one.

Iniciar sesión para comentar.


Dan W
Dan W el 23 de En. de 2015
I'm not sure if this is new syntax or not, but it works with R2012a and it's fast and simple.
x = rand(100);
tic;
x([3,9],:) = [];
toc; % Elapsed time is 0.000230 seconds.
  3 comentarios
Andrei Bobrov
Andrei Bobrov el 10 de Jun. de 2016
Hi Mehul! It new question.
Andrei Bobrov
Andrei Bobrov el 10 de Jun. de 2016
out = m1;
out(m2,:) = [];

Iniciar sesión para comentar.


Andrei Bobrov
Andrei Bobrov el 21 de Jun. de 2012
m = m(setdiff(1:size(m,1),[3,9]),:);
  5 comentarios
Jan
Jan el 22 de Jun. de 2012
SETDIFF has a remarkable overhead. ISMEMBER is smarter and twice as fast for a 100x100 matrix:
m = m(~ismember(1:size(m, 1), [3,9]), :);
pradeep kumar
pradeep kumar el 30 de Ag. de 2014
@ Andrei Bobrov , @ Walter Roberson,@ Jan Simson . how delete a particular row and column of a matrix by using "setdiff" . Say m= [1 2 3 4 ; 5 6 7 8; 9 10 11 12 ; 13 14 15 16 ]. i want to delete 1st row and 2nd column to obtain m=[5 7 8; 9 11 12;13 15 16]

Iniciar sesión para comentar.


Alireza Rezvani
Alireza Rezvani el 19 de Jun. de 2016
sry, how i can Deleting individual columns of a matrix, any body know?
  2 comentarios
Muhammad Usman Saleem
Muhammad Usman Saleem el 19 de Jun. de 2016
Assume out is your matrix and you want to delete its first column, try this code,
out(:,1) = [];
surendra bala
surendra bala el 31 de Mzo. de 2018
Yes. This is the easiest way you can do.

Iniciar sesión para comentar.


zshockz
zshockz el 10 de Oct. de 2016
So I have to make a function that is able to delete a row in a matrix [I have 3 by 3]. I am not sure how to do this, please leave any help you can!

LISSA DUVVU
LISSA DUVVU el 29 de Sept. de 2018
i want to delete all columns data where the 4th row contains number 7
  1 comentario
Jan
Jan el 7 de Oct. de 2018
Please do not attach a new (and very vague) question in the section for answers of another questions. Such thread-hijacking is confusing only, because it is not longer clear, to which question an answer belong. Please open your own question and delete this pseudo-answer. Thanks.

Iniciar sesión para comentar.

Categorías

Más información sobre Logical 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