Basic if statement with a cell array

1 回表示 (過去 30 日間)
012786534
012786534 2017 年 4 月 12 日
回答済み: the cyclist 2017 年 4 月 12 日
Hello all,
Let's say I have a basic cell array : x = {1 2 3 4 5 8}. Now, I want to verify that this array only contains those numbers and if not return an error message.
Like so:
if x ~= 1 | 2 | 3 | 4 | 5 | 8
disp('error');
end
How would I make this work? Please note that it needs to remain a cell array.
Thank you

回答 (1 件)

the cyclist
the cyclist 2017 年 4 月 12 日
If I understand correctly, this will work
if not(all(ismember(cell2mat(x),[1 2 3 4 5 8])))
disp('error');
end

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by