Display a variable and its units
234 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ryan
el 3 de Dic. de 2011
Comentada: Michael Darwish
el 12 de Dic. de 2021
I know how to use the display(X) function to display a variable I have solved for. So, if my X = 25, and I need it to display 25 ft/lb, how would I do this?
1 comentario
Respuesta aceptada
Karan Gill
el 7 de Abr. de 2017
Editada: Karan Gill
el 17 de Oct. de 2017
Units are now in MATLAB if you have Symbolic Math Toolbox. Try this, and see the tutorial: https://www.mathworks.com/help/symbolic/units-of-measurement-tutorial.html:
>> u = symunit;
>> x = 2*u.meter
x =
2*[m]
>> x = rewrite(x,u.ft)
x =
(2500/381)*[ft]
>> double(separateUnits(x))
ans =
6.5617
3 comentarios
Samuel Katongole
el 19 de Mzo. de 2020
I am also looking for somwthing similar to what Damien is looking for, but mine is when i want to print thw units along with the values especially using the fprintf function....I too need help here..
Husam Alsaleh
el 24 de Sept. de 2020
i am also using fprintf and i need to display my units next to the numbers
Más respuestas (3)
Thomas Green
el 22 de Feb. de 2018
Editada: Thomas Green
el 22 de Feb. de 2018
Hey, I just want to thank you guys for 1. always making it more complicated than it needs to be 2. adding statements/functions that are never really seen but could have easily could have produced the same result with a common command and most importantly 3.NEVER SHOWING AN OUTPUT. Like do you really think you are helping????
2 comentarios
Sven
el 3 de Dic. de 2011
You can use fprintf as follows:
X = 25;
fprintf('The answer is %d ft/lb\n', X)
If your answer will not be a nice round number like "25", you can replace the %d above with, say, %0.2f to print two decimal places.
5 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!