How to do if condition on the type of data
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Behrooz Daneshian
le 30 Déc 2022
Réponse apportée : Walter Roberson
le 30 Déc 2022
Hi all,
I want to creat if condition in MATLAB in a way that if type of my data is cell, do something and else, do something else. I know that type of data can be determined using class(data). Would you please guide me in this regard?
0 commentaires
Réponse acceptée
Walter Roberson
le 30 Déc 2022
%preparation
if rand() < 0.5
C = 23;
else
C = {23, 'skidoo'};
end
%now we need to know the type of C to progress
if iscell(C)
disp('was cell')
output = C{1} * 2;
else
disp('was not cell')
output = C(1) * 2;
end
output
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Structures dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!