Check if cell contains only certain combination of variables
古いコメントを表示
I have a 4x1 cell filled with 4 possible string values: 'A', 'B', 'C', or 'D'
I would like to ensure that the values in there either:
any combination of: 'A' and/or 'B'
OR
any combination of 'C' and/or 'C'
But I want to raise an error if there is any mix between say A and C, or A and D, and so forth
3 件のコメント
Turlough Hughes
2022 年 1 月 31 日
Are there 4 letters in each cell or just one? Can you give an example of the cell array?
Metin Akyol
2022 年 1 月 31 日
Metin Akyol
2022 年 1 月 31 日
採用された回答
その他の回答 (1 件)
Benjamin Thompson
2022 年 1 月 31 日
0 投票
So something like this? I am sure you can add more detail to deal with all possible cases.
myCellArray{1} = 'A';
myCellArray{2} = 'B';
myCellArray{3} = 'C';
myCellArray{4} = 'D';
if (myCellArray{1} == 'A')
for (i = 2:4)
if ((myCellArray{i} == 'C') || (myCellArray{i} == 'D'))
disp('Not Good')
end
end
end
カテゴリ
ヘルプ センター および File Exchange で Structures についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!