Delete row from Matrix

조회 수: 598 (최근 30일)
Nancy
Nancy 2012년 6월 21일
댓글: muhammad usama 2023년 5월 7일
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
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
Gokul Krishna N 2020년 11월 2일
Thanks

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2012년 6월 22일
편집: MathWorks Support Team 2018년 11월 9일
If you have a matrix A and want to delete the 3rd and 9th rows, you can use the command:
A([3,9],:) = [];
  댓글 수: 5
Walter Roberson
Walter Roberson 2019년 6월 18일
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 2021년 10월 7일
Thank you so much Jan!

댓글을 달려면 로그인하십시오.

추가 답변 (5개)

Peter
Peter 2012년 11월 30일
"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
muhammad usama
muhammad usama 2023년 5월 7일
Thank you, the simplest one.

댓글을 달려면 로그인하십시오.


Dan W
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
Andrei Bobrov
Andrei Bobrov 2016년 6월 10일
Hi Mehul! It new question.
Andrei Bobrov
Andrei Bobrov 2016년 6월 10일
out = m1;
out(m2,:) = [];

댓글을 달려면 로그인하십시오.


Andrei Bobrov
Andrei Bobrov 2012년 6월 21일
m = m(setdiff(1:size(m,1),[3,9]),:);
  댓글 수: 5
Jan
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
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
Alireza Rezvani 2016년 6월 19일
sry, how i can Deleting individual columns of a matrix, any body know?
  댓글 수: 2
Muhammad Usman Saleem
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
surendra bala 2018년 3월 31일
Yes. This is the easiest way you can do.

댓글을 달려면 로그인하십시오.


LISSA DUVVU
LISSA DUVVU 2018년 9월 29일
i want to delete all columns data where the 4th row contains number 7
  댓글 수: 1
Jan
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by