Cell Arrays causing problem with Subsetting

1 回表示 (過去 30 日間)
Metin Akyol
Metin Akyol 2022 年 2 月 12 日
コメント済み: Metin Akyol 2022 年 2 月 12 日
I am trying to create a subset of a table like so (which works fine)
cond1 = "random_name"
table2= (table1.col1 == cond1,:)
Now, instead, when I define cond1 as the first element from another table (which has only one column with only strings) like so:
cond2 = table3{1,:}
the new string has only single quotation marks:
'random_name'
This however causes the following error:
table2= (table1.col2 == cond1,:)
Operator '==' is not supported for operands of type cell. Now I could used strcmp instead:
table2= (strcmp (table1.col2 ,cond1),:)
But I am wondering if there is a simpler solution to this problem?

採用された回答

Image Analyst
Image Analyst 2022 年 2 月 12 日
編集済み: Image Analyst 2022 年 2 月 12 日
Like it said you need to be using contains() or strcmpi() instead of ==.
No simpler way.
Attach your table in a .mat file if you need more help so we can try additional things.
  1 件のコメント
Metin Akyol
Metin Akyol 2022 年 2 月 12 日
Got it, thank you, I appreciate the help. I'll stick to strcmp then.
For my reproducable version, Table3 itself is pretty simple, just 1X1 size and contains only that one string.

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by