필터 지우기
필터 지우기

How to delete the last n elements of an array?

조회 수: 114 (최근 30일)
MatlabFan
MatlabFan 2013년 3월 11일
편집: franco otaola 2020년 4월 15일
Hi, I am trying to delete the bottom n rows of an N X 2 array. I don't know how to do it. Would you please help?
For example, suppose that I have the matrix M=[3 6 3 7 9 11 5 34; 1 4 6 8 98 3 4 45]. I would like to delete the, say,the bottom 2 rows to get the new M=[3 6 3 7 9 11; 1 4 6 8 98 3]
How can I do this?
Please help.
Thank you.

채택된 답변

Miroslav Balda
Miroslav Balda 2013년 3월 11일
It is simple
M = M(1:end-2,:)
  댓글 수: 3
Image Analyst
Image Analyst 2017년 8월 19일
"1:end-2" specified rows from 1 through 2 before the last row. Now you need to specify the columns since M is a 2-D matrix with both rows and columns. The comma separates the rows specifier from the column specifier. The column specifier is ":" which means "all". So it means rows 1 through the end-2 and all columns of those rows.
franco otaola
franco otaola 2020년 4월 15일
편집: franco otaola 2020년 4월 15일
hello,
i knew how to do it, but to do this, you have to have M decleared before, i find myself with this problem all the time in matlab and obviously it is that i am missing something:
for example i am calculating a convolution of signals (it is just an example of where i find myself with this issue),
S1=[1:1:100]'; %for S1 and h i took simpler examples of arrays to be more clear
h=[1:1:100]';
O1=conv(S1,h); %my problem is that i want to cut the O1 to the same size as S1
% and h, as the rest of the convolution is going to be 0
%{
so i would like to do something like this
O1=conv(S1,h)(1:100);
i know i can do:
O1=conv(S1,h);
O1=O1(1:100); but is it possible to do it in one line?
%}
best regards, franco!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by