Problem using str2num/str2double

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 comentario

Walter Roberson
Walter Roberson el 12 de Sept. de 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?

Iniciar sesión para comentar.

Respuestas (1)

Tim Jackman
Tim Jackman el 15 de Sept. de 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 comentarios

Shivani Rani
Shivani Rani el 16 de Sept. de 2015
Editada: Shivani Rani el 16 de Sept. de 2015
Thanks for the reply. Basically, I am using a .m file to process the output results at nodes and in elements. Str2num function has been used to covert the string into number. That file is working with smaller amount of load, i.e. 200. The same file was not working for 1000 or 1000s load. I changed str2num to str2double, the file run. However, I was getting all NaN values. I did not change anything else. There is no underscore problem.
Walter Roberson
Walter Roberson el 16 de Sept. de 2015
What does "load" mean in this context? Is it the number of rows in the file? Is it the number of lines in the file? Is it the size() of a cell array of strings?
When you say that it is not working, what do you see when you try with the higher "load" ?
Shivani Rani
Shivani Rani el 22 de Sept. de 2015
Load is a variable. Basically, I am using Matlab to process the output files. Here, I run the same pavement model with different loads and process the output file. At smaller load (vertical load), the file run; however, at the higher value of load, the same file is giving the problem (see below):
>> Subscripted assignment dimension mismatch.
Error in createOUTfilesStat (line 68) Lineelem(j2-6,:) = str2num([Lineelem1 Lineelem2]);
Error in MainMatlab_DSC (line 27) [Elem_out, Node_out] = createOUTfilesStat(finput,Nnode,4*Nelem);
>>
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 el 24 de Sept. de 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.

Iniciar sesión para comentar.

Categorías

Más información sobre Data Type Conversion en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 12 de Sept. de 2015

Comentada:

el 24 de Sept. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by