How to delete every "n thru m" rows?

13 ビュー (過去 30 日間)
Nicole Ralbovsky
Nicole Ralbovsky 2021 年 4 月 22 日
編集済み: David Hill 2021 年 4 月 22 日
I have a matrix which contians 27, 260 rows and one column. I need to delete every 151-181 rows of the data set. Is there a code with which I can do this? Essentially, instead of wanting to delete every "n" rows, I want to delete every "n thru m" rows. Thanks.

回答 (1 件)

David Hill
David Hill 2021 年 4 月 22 日
I might not understand your question fully. What is the size of your matrix? (260x1)
yourMatrix(151:181,:)=[];%deletes rows in matrix
  2 件のコメント
Nicole Ralbovsky
Nicole Ralbovsky 2021 年 4 月 22 日
編集済み: Nicole Ralbovsky 2021 年 4 月 22 日
Thanks for the quick response. The matrix is 27460x1 and I would like to delete every 151-181 rows. So instead of deleting every 151 ("nth") row, I want to delete every 151-181 rows.
David Hill
David Hill 2021 年 4 月 22 日
編集済み: David Hill 2021 年 4 月 22 日
Just add nan to end of matrix so you can reshape, and remove nan at end of operation.
yourMatrix(end+1:27512)=nan;
yourMatrix=reshape(yourMatrix,181,[]);
yourMatrix(151:181,:)=[];
yourMatrix=yourMatrix(:);
yourMatrix(isnan(yourMatrix))=[];

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by