Need help using num2str?

14 visualizaciones (últimos 30 días)
Kelsey
Kelsey el 10 de Feb. de 2014
Comentada: Thomas Seers el 10 de Feb. de 2014
I am trying to display the sentence:
The approximate work done is {W} kJ.
(Where W is the calculated work variable) How can I do this using just one line? I'm fairly certain I need to use the num2str command. Thanks in advance!
Right now this is what I have, but I want it to be all one line...
disp('The approximate work done is: ')
disp(W)
disp('kJ')

Respuestas (1)

the cyclist
the cyclist el 10 de Feb. de 2014
Editada: the cyclist el 10 de Feb. de 2014
disp(['The approximate work done is: ',num2str(W),' kJ'])
The way I personally approach constructing things like this is to first write out the sentence without using the variable:
disp(['The approximate work done is: 123 kJ'])
then isolate the numeric piece, using concatenation:
disp(['The approximate work done is: ','123',' kJ'])
and then substitute in the num2str as above.
  3 comentarios
the cyclist
the cyclist el 10 de Feb. de 2014
The best form of thank you is accepting the answer. :-)
Thomas Seers
Thomas Seers el 10 de Feb. de 2014
Accept the answer Kelsey!

Iniciar sesión para comentar.

Categorías

Más información sobre Mathematics en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by