Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
TheSaint
TheSaint am 1 Feb. 2024
Kommentiert: TheSaint am 2 Feb. 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)

Akzeptierte Antwort

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Startup and Shutdown 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