How to add an input to the end of an fprintf function

5 次查看(过去 30 天)
units = input('Please enter the units for your rectangular coordinates: ','s');
I have this line of code right here. I would like the user to enter the units, and then have them display after this line of code below:
fprintf('Our rectangular coordinates converted to cylindrical coordinates are (%0.2f,%0.2f,%0.2f)' , r, lambda, phi )
For example, if the units are in mm, I just need the code to read: (r , lambda, phi) mm
I tried using this code below, but it was unsuccessful.
fprintf('Our rectangular coordinates converted to cylindrical coordinates are (%0.2f,%0.2f,%0.2f)' , r, lambda, phi ) + units

采纳的回答

Star Strider
Star Strider 2024-2-3
Perhaps this —
r = rand;
lambda = rand;
phi = rand;
units = 'mm';
fprintf('Our rectangular coordinates converted to cylindrical coordinates are (%0.2f,%0.2f,%0.2f) %s' , r, lambda, phi, units)
Our rectangular coordinates converted to cylindrical coordinates are (0.76,0.79,0.03) mm
.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 NaNs 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by