round (returning a number)
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
i have a value: a = 1.50000 and i want to round it to 1.5 as a number
i use: a = num2str(a, '%7.1')
now: a = 1.5 but it is a string
so i use: a = str2num(a)
but now: a = 1.50000
Argghhh
0 comentarios
Respuesta aceptada
Fangjun Jiang
el 30 de Ag. de 2011
What do you mean round in this case? If a=1.50123 and you want a=1.5, that is rounding. If a=1.50000, and you want a=1.5, that's just visual.
>> a=1.5
a =
1.5000
>> format short g
>> a
a =
1.5
If you want to put it in a uitable for example, the column format of "short g" still has 4 digits of precision, which means 1.5000. So it looks like you have to first make it string format like you did. To put it in a table anywhere else, you can use num2str() or fprintf('%7.1')
0 comentarios
Más respuestas (0)
Ver también
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!