Filter löschen
Filter löschen

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

2 Ansichten (letzte 30 Tage)
TheSaint
TheSaint am 3 Feb. 2024
Kommentiert: Star Strider am 3 Feb. 2024
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

Akzeptierte Antwort

Star Strider
Star Strider am 3 Feb. 2024
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
.

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Produkte


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by