Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
TheSaint
TheSaint le 3 Fév 2024
Commenté : Star Strider le 3 Fév 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

Réponse acceptée

Star Strider
Star Strider le 3 Fév 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
.
  2 commentaires
TheSaint
TheSaint le 3 Fév 2024
Thank you!
Star Strider
Star Strider le 3 Fév 2024
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by