Effacer les filtres
Effacer les filtres

How do I put a variable input inside a char vector?

1 vue (au cours des 30 derniers jours)
TheSaint
TheSaint le 1 Fév 2024
Commenté : TheSaint le 2 Fév 2024
fprintf('Car number' 'is driving the fastest', x)
I have this function, and I want to put an input command such as this in between 'Car number' and 'is driving...'
CarNumber = input('Please enter the car number')
Is there a way I can do this? I tried using this line below, but it was unsuccessful
fprintf('Car number'CarNumber 'is driving the fastest', x)

Réponse acceptée

Voss
Voss le 1 Fév 2024
CarNumber = input('Please enter the car number: ');
fprintf('Car number %d is driving the fastest\n', CarNumber);
  2 commentaires
Walter Roberson
Walter Roberson le 1 Fév 2024
Or
fprintf("Car number " + CarNumber + " is driving the fastest\n")
TheSaint
TheSaint le 2 Fév 2024
Thanks Walter, this worked for me

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Startup and Shutdown 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