Borrar filtros
Borrar filtros

Cell values to numbers

3 visualizaciones (últimos 30 días)
Jay
Jay el 24 de Abr. de 2016
Comentada: Image Analyst el 24 de Abr. de 2016
So I have cell (1 x 2) created using the strsplit command (DMS = strsplit(StrVal, '.')).
I then use the cell2mat command to convert the cell values to characters (M_Mat = cell2mat(DMS(1,2))).
I then use the str2num command to obtain numerical values (M_Num = Str2double(M_Mat)).
The test value in M_Mat is 0001.
The returned value in M_Num = 1
How do I get the M_Num to equal 0001?
The M_Num value is used to assess validity of a condition in a later if statement (thus be of the type number or double).
Do I need to put the decimal point back into to the value just after the strsplit command (thus specifying it as a decimal value) and if so how do I do that in a cell?
  1 comentario
Jan
Jan el 24 de Abr. de 2016
I do not understand the problem. If you want '0001', simply omit the str2double .
It would be easier to understand the code, if you post the input data and the code in a form, which runs by copy&paste.

Iniciar sesión para comentar.

Respuestas (1)

Image Analyst
Image Analyst el 24 de Abr. de 2016
If you want to have leading zeros in there, then you'll have to leave it as a string, because, of course, 00001 is the same as 1 if you're dealing with numbers. Or else leave it as a number less than 1 like you said.
  2 comentarios
Jay
Jay el 24 de Abr. de 2016
Ok, I would like to use a cell value that has an integer number and input the decimal point preceding said value in a created cell.
How do I do that?
Image Analyst
Image Analyst el 24 de Abr. de 2016
To get the fractional part, subtract the integer part:
fractionalPart = abs(theNumber) - floor(theNumber);
If you need to keep the sign, then multiply by sign(theNumber).

Iniciar sesión para comentar.

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by