Creating subset of table

156 ビュー (過去 30 日間)
Metin Akyol
Metin Akyol 2022 年 2 月 9 日
コメント済み: Stephen23 2022 年 2 月 10 日
When I am trying to create a subset of my table like so:
table_1(table_1.col_1>=0,:)
I am getting this error:
Operator '>=' is not supported for operands of type 'cell'
col_1 contains numbers, but they might not be recognized as numerical var type. Is there an elegant solution to this.
I have been trying strcmp instead, but that does not work on numerical comparisons.
I also tried to convert the column to an array using cell2mat but then I ned up getting an error saying:
Row index exceeds table dimesions.
  1 件のコメント
Stephen23
Stephen23 2022 年 2 月 10 日
"col_1 contains numbers, but they might not be recognized as numerical var type. Is there an elegant solution to this."
The first thing to try is STR2DOUBLE.
If that does not work then upload your data in a .mat file by clicking the paperclip button.

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

回答 (1 件)

Scott MacKenzie
Scott MacKenzie 2022 年 2 月 9 日
編集済み: Scott MacKenzie 2022 年 2 月 9 日
Since column 1 contains numbers in cells, something like this is needed:
T = array2table([{1, -2, 3}' {'a' 'b' 'c'}']) % test data
T = 3×2 table
Var1 Var2 ______ _____ {[ 1]} {'a'} {[-2]} {'b'} {[ 3]} {'c'}
T.Var1 = cell2mat(T{:,1})
T = 3×2 table
Var1 Var2 ____ _____ 1 {'a'} -2 {'b'} 3 {'c'}
T(T.Var1 >= 0,:)
ans = 2×2 table
Var1 Var2 ____ _____ 1 {'a'} 3 {'c'}
  5 件のコメント
Metin Akyol
Metin Akyol 2022 年 2 月 10 日
Your initial table T is also different than my starting table, in the sense that your table has T.Var1 being a 3x1 cell, my column is a cell array.
Scott MacKenzie
Scott MacKenzie 2022 年 2 月 10 日
Moving forward, it would be best if you post your data and the code that generates the error. Of course, you can also just post a subset of your data along with code demonstrating the error.

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

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by