Removing rows of table based on logical array
32 ビュー (過去 30 日間)
古いコメントを表示
Hello, I have an imported table of data that is 122 x 11.
I have identified an xdata and ydata I want to use, and have named them such.
ydata comes from column 7 of my table.
I am singling out the heighest 10 values in this column by using
topTenData = maxk(ydata, 10)
that identified a minimum value of 1.01, and I'm uninterested in any data below that value.
I am attempting to get rid of all rows that are smaller than this using (remember column 7 is ydata):
TT = data(:,7) < 1.01
data(TT,:) = []
What I expect to happen is anywhere in which TT returns true, the row will be removed.
Instead, I get an error stating:" A table row subscript must be a numeric array containing real positive integers, a logical array, a character vector, a string-array, a cell array of character vectors, or a pattern scalar."
Does this mean that if my raw data rows have a multitude of different types of data within each column, it is not possible to delete the rows this way? If so, can I get some guidance on a better method? Thanks!
0 件のコメント
採用された回答
Voss
2023 年 7 月 1 日
I think the problem is with this line:
TT = data(:,7) < 1.01
With data being a table, I get the error, "Undefined operator '<' for input arguments of type 'table'."
Instead of using parentheses ( ) you should use curly braces { } to access the contents of a table, as in:
TT = data{:,7} < 1.01
Then that line will run and TT will be a logical vector you can use to delete rows from the table as you intend.
Here's a simple complete example to illustrate:
% a table with two columns:
data = table(randi(10,10,1),randi(10,10,1))
% a logical vector saying whether the data in column 2 is less than 4.
% Note: use curly braces {} to access the contents of a table.
TT = data{:,2} < 4
% remove those rows from the table:
data(TT,:) = []
2 件のコメント
Peter Perkins
2023 年 7 月 17 日
編集済み: Peter Perkins
2023 年 7 月 17 日
Voss is correct up to a point, but there is some late-breaking R2023a news that changes the story. Please see my comment in another thread:
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Data Type Identification についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!