Basic if statement with a cell array
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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
0 Commenti
Risposte (1)
the cyclist
il 12 Apr 2017
If I understand correctly, this will work
if not(all(ismember(cell2mat(x),[1 2 3 4 5 8])))
disp('error');
end
0 Commenti
Vedere anche
Categorie
Scopri di più su Data Types in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!