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

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)

 Accepted Answer

CarNumber = input('Please enter the car number: ');
fprintf('Car number %d is driving the fastest\n', CarNumber);

2 Comments

Or
fprintf("Car number " + CarNumber + " is driving the fastest\n")
Thanks Walter, this worked for me

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2023b

Asked:

on 1 Feb 2024

Commented:

on 2 Feb 2024

Community Treasure Hunt

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

Start Hunting!