Effacer les filtres
Effacer les filtres

How to delete the last n elements of an array?

109 vues (au cours des 30 derniers jours)
MatlabFan
MatlabFan le 11 Mar 2013
Modifié(e) : franco otaola le 15 Avr 2020
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.

Réponse acceptée

Miroslav Balda
Miroslav Balda le 11 Mar 2013
It is simple
M = M(1:end-2,:)
  3 commentaires
Image Analyst
Image Analyst le 19 Août 2017
"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 le 15 Avr 2020
Modifié(e) : franco otaola le 15 Avr 2020
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!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by