Delete row from Matrix
显示 更早的评论
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 个评论
Yuvraj Praveen Soni
2019-12-9
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
2020-11-2
Thanks
采纳的回答
更多回答(5 个)
Peter
2012-11-30
32 个投票
"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
Dan W
2015-1-23
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 个评论
Mehul Agrawal
2016-6-10
Thanks, this works pretty easy. But I have a problem where the elements to remove are decided dynamically. So, I have a matrix m1 of size 100 X 100. And another matrix m2 of size 10X1. m2 has the row number to remove from m1 (they are not in any order). What is the best way to do this ?
Eg: m1 = rand(100); m2 = [1,6,4,8,10]; (this is the output of another function call).
Andrei Bobrov
2016-6-10
Hi Mehul! It new question.
Andrei Bobrov
2016-6-10
out = m1;
out(m2,:) = [];
Andrei Bobrov
2012-6-21
m = m(setdiff(1:size(m,1),[3,9]),:);
5 个评论
Sean de Wolski
2012-6-21
mmm glass half full
Ryan
2012-6-21
Anyone care to explain this one?
Walter Roberson
2012-6-21
It copies the rows of m that are _not_ row 3 or 9.
Jan
2012-6-22
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
2014-8-30
@ 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]
Alireza Rezvani
2016-6-19
5 个投票
sry, how i can Deleting individual columns of a matrix, any body know?
2 个评论
Muhammad Usman Saleem
2016-6-19
Assume out is your matrix and you want to delete its first column, try this code,
out(:,1) = [];
surendra bala
2018-3-31
Yes. This is the easiest way you can do.
LISSA DUVVU
2018-9-29
1 个投票
i want to delete all columns data where the 4th row contains number 7
1 个评论
Jan
2018-10-7
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.
类别
在 帮助中心 和 File Exchange 中查找有关 Multidimensional Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!