Problem using str2num/str2double

7 vues (au cours des 30 derniers jours)
Shivani Rani
Shivani Rani le 12 Sep 2015
Commenté : Shivani Rani le 24 Sep 2015
I made a matlab using str2num. When increased the load, str2num was not working. I changed str2num to str2double. I got NaN istead of getting any number. Please send me your email-id if u want me to send the .m file. But, I can't post online.
  1 commentaire
Walter Roberson
Walter Roberson le 12 Sep 2015
Please clarify what you mean by "increased the load"?
If you disp() the string that you are trying to convert, what does it show up as?

Connectez-vous pour commenter.

Réponses (1)

Tim Jackman
Tim Jackman le 15 Sep 2015
Without seeing the string you are trying to convert, there is not much advice I can give other than to check the string and see if you have any weird characters. For example, the presence of an underscore will cause problems similar to what you describe:
>> test = '3_5';
>> str2num(test)
ans =
[]
>> str2double(test)
ans =
NaN
  5 commentaires
Walter Roberson
Walter Roberson le 22 Sep 2015
Time to learn how to use the debugger.
Give the command
dbstop if error
and run your program. When it halts with this error, ask
disp([[Lineelem1 Lineelem2])
size(str2num([Lineelem1 Lineelem2]))
size( Lineelem(j2-6,:) )
Shivani Rani
Shivani Rani le 24 Sep 2015
Thank you very much for your help. I figured out the problem in my file. At higher loads, two values got merged (no space in between) in my output text files. So matlab could not read those number correctly and hence, I was getting dimension mismatch error.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Data Type Conversion 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