Trying to delete rows in a table based on specific values using indexing

10 ビュー (過去 30 日間)
Haley Royer
Haley Royer 2022 年 7 月 22 日
コメント済み: Voss 2022 年 7 月 22 日
I have a variable with 3 columns and 343127 rows. I'm trying to delete rows based on values in the 3rd column using the following method that I got from another question in the community here:
idx = any(PARTidMat<738341.7917 | PARTidMat>738342,3);
out = PARTidMat(idx,:);
PARTidMat(idx,:) = [];
PARTidMat is the variable I'm trying to delete rows from. Rows containing 738341.7917 - 738342 in column 3 are the rows I'm trying to delete. I don't have any issues running line 1. It produces a logical variable with the same dimensions as my PARTidMat variable. Columns 1 and 2 all have logical values of 1 and column 3 has 0 values where the values meet the parameters set in the idx line of code (I checked this in excel).
When I run line 2, I get the following error:
The logical indices in position 1 contain a true value outside of the array bounds.
When I run the 3rd line, I get the following error (maybe because line 2 doesn't work, but maybe for a different reason?):
Matrix index is out of range for deletion.
I'm not sure what I'm doing wrong here. Can anyone help me out?

採用された回答

Voss
Voss 2022 年 7 月 22 日
編集済み: Voss 2022 年 7 月 22 日
Instead of this:
idx = any(PARTidMat<738341.7917 | PARTidMat>738342,3); % any along the 3rd dimension
Do this:
idx = PARTidMat(:,3) < 738341.7917 | PARTidMat(:,3) > 738342; % those in the 3rd column
  4 件のコメント
Haley Royer
Haley Royer 2022 年 7 月 22 日
That works!! Thank you so much. You've no idea how much this has been frustrating me. Cheers!
Voss
Voss 2022 年 7 月 22 日
I'm glad it's working now!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by