フィルターのクリア

How to delete the last n elements of an array?

109 ビュー (過去 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 Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by