Trying to display text and variable in a single output line. I was initially trying to use disp then a matrix then fprintf

339 次查看(过去 30 天)
desired output:
The answer is: 800 %
I am trying to display this sentence in a single line of output in the command window. thankyou

采纳的回答

b m
b m 2019-3-3
name = 'Alice';
age = 12;
X = [name,' will be ',num2str(age),' this year.'];
disp(X)
I FOUND A SAMPLE I WORKED OFF OF
thanyou

更多回答(1 个)

Milly
Milly 2024-6-19
编辑:Milly 2024-6-20
Not quite sure what issue the author had with the "disp" function but this should be the most efficient way to do this.
The given example would look like this:
var1 = 800;
disp("The answer is: " + var1 + " %")
The answer is: 800 %
The accepted answer using the disp function would look like this:
name = "Alice";
age = 12;
disp(name + " will be "+ age + " this year.")
Alice will be 12 this year.

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by