Effacer les filtres
Effacer les filtres

Equal Cell

96 vues (au cours des 30 derniers jours)
Pepa
Pepa le 18 Mar 2011
Hallo,
how can i use condition "if", if i have two variables type cell? For examlpe:
if(datLab(k)==label(i))
disp(datLab(k));
else
disp('No exist');
end
end
datLab and label are variables cell (string).
Thanks

Réponse acceptée

Walter Roberson
Walter Roberson le 18 Mar 2011
if strcmp(datLab{k}, label{i})
or
if isequal(datLab{k}, label{i})
  1 commentaire
Pepa
Pepa le 18 Mar 2011
Thank you!!!

Connectez-vous pour commenter.

Plus de réponses (1)

Laura Proctor
Laura Proctor le 18 Mar 2011
To get the contents of a cell, use the curly braces. For example:
v1 = {2};
v2 = {2};
if v1{1} == v2{1}
disp(['v1 = v2 = ',num2str(v1{1})])
else
disp('not equal')
end
  1 commentaire
Walter Roberson
Walter Roberson le 18 Mar 2011
The original poster indicated that the values are strings; using == to compare strings does not work unless the strings are exactly the same length. strcmp() or isequal() do not have that difficulty.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by