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)

 採用された回答

Voss
Voss 2024 年 2 月 1 日

0 投票

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

2 件のコメント

Walter Roberson
Walter Roberson 2024 年 2 月 1 日
Or
fprintf("Car number " + CarNumber + " is driving the fastest\n")
TheSaint
TheSaint 2024 年 2 月 2 日
Thanks Walter, this worked for me

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMATLAB についてさらに検索

製品

リリース

R2023b

質問済み:

2024 年 2 月 1 日

コメント済み:

2024 年 2 月 2 日

Community Treasure Hunt

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

Start Hunting!

Translated by