logical operation with categorical data
3 ビュー (過去 30 日間)
古いコメントを表示
I have 6 csv files with one of the variables in the csv file containing names of players. I want to perform operations only if the name in the particular file is the name of a certain player. When I perform the logical operation in the 'if' line, I get an error. Am I performing the logical operation incorrectly? Is there a different way to do logical operations with categorical data?
for i = 1:6
csv = readtable(file(i).name);
K=categorical(csv.Var2(2)); %% reads the player name as categorical data.
if K=='Ronaldo'||'Messi'||'Neymar' % Only enter the loop if K is one of these players names
m=0;
m=m+1;
end
end
2 件のコメント
採用された回答
Rik
2021 年 12 月 1 日
This depends a bit on your source data, but you should look at the ismember function. Especially when combined with any, it really helps in these situations. Alternatively you could look at switch, which also allows multiple case definitions.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Categorical Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!