Creating subset of table
138 次查看(过去 30 天)
显示 更早的评论
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
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
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.Var1 = cell2mat(T{:,1})
T(T.Var1 >= 0,:)
5 个评论
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 Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!