comparison between a string/or cell and categorical data
4 次查看(过去 30 天)
显示 更早的评论
hi,i ve this problem
Trading=categorical({'As is';'bla'})
B='As is';
class(B)='char'
b==Trading(1)
> 0
how can i compare a value of type char and a categorical data type?
(
0 个评论
回答(2 个)
Steven Lord
2023-6-4
MATLAB is correct.
Sis(1).Trading = 'As Is'
Trading(1) = categorical({'As is'})
Sis(1).Trading==Trading(1)
If you used a capital I in the definiition of Trading or a lower-case i in the definition of Sis(1).Trading you'd receive the results you expected.
SisLC.Trading = 'As is';
SisLC.Trading == Trading(1)
TradingUC = categorical({'As Is'});
Sis(1).Trading == TradingUC
the cyclist
2023-6-4
Your method works for me:
Trading = categorical({'As is';'bla'});
B='As is';
B == Trading(1)
You did have a lower-case "b" in your code. MATLAB is case-sensitive. Maybe that was part of the problem?
5 个评论
the cyclist
2023-6-4
We don't need another example. Please upload your data. You can use the paper clip icon in the INSERT section of the toolbar.
As I said above, I can define the variables myself and get your example to work. The key to understanding your problem is to use the data you are actually working with.
Trading(1) = categorical({'As Is'});
v = 'As Is';
Trading(1) == v
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Transaction Cost Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!