How can I make matlab stop recognizing string as char?

16 vues (au cours des 30 derniers jours)
Andres
Andres le 23 Sep 2012
I assigned
wavetype = 'sawtooth';
and matlab keeps telling me wavetype is a 1X8 char which is preventing me from using the strcomp() function later when I
if strcomp(wavetype,'sawtooth')
How can I make sure the variable is considered a string?
  1 commentaire
Jan
Jan le 23 Sep 2012
Modifié(e) : Jan le 23 Sep 2012
Whenever you post a problem in a forum, add the complete error message. Currently we can only guess, what "strcomp" could be and what error message you exactly get.
"Strings" are CHAR vectors in Matlab, therefore it is unlikely that you have to interprete them as anything else.

Connectez-vous pour commenter.

Réponse acceptée

Sven
Sven le 23 Sep 2012
I think the issue here is just a typo:
"strcomp" is not a MATLAB function. I think you mean "strcmp".
wavetype = 'sawtooth';
if strcmp(wavetype,'sawtooth')
disp('We got a sawtooth!')
else
disp('We got something else...')
end
Did that solve it for you Andres?

Plus de réponses (0)

Catégories

En savoir plus sur Logical 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!

Translated by