Borrar filtros
Borrar filtros

How to delete the last n elements of an array?

114 visualizaciones (últimos 30 días)
MatlabFan
MatlabFan el 11 de Mzo. de 2013
Editada: franco otaola el 15 de Abr. de 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.

Respuesta aceptada

Miroslav Balda
Miroslav Balda el 11 de Mzo. de 2013
It is simple
M = M(1:end-2,:)
  3 comentarios
Image Analyst
Image Analyst el 19 de Ag. de 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 el 15 de Abr. de 2020
Editada: franco otaola el 15 de Abr. de 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!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by