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일

0 개 추천

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월 9일
Thank you for that. Didn't quite work for me though, still getting the same error. That transformation that you suggested, still leaves my column unchanged, i.e. it is still a cell array.
Scott MacKenzie
Scott MacKenzie 2022년 2월 9일
Ok, I just did a little edit to the answer. I'm assuming column 1 contains numbers only in cells.
Metin Akyol
Metin Akyol 2022년 2월 10일
I am still getting the same error saying that Row index exceeds table dimensions when I use cell2mat. In fact, using cell2mat converts the column to a struct with fields on my end.
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.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Data Type Conversion에 대해 자세히 알아보기

제품

릴리스

R2021a

태그

질문:

2022년 2월 9일

댓글:

2022년 2월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by