假设我有一个变量 A=5
我想输出它,但在它的前后添加了一些文本。像这样:"There are 5 horses."
(请注意 5
应该是可变变量 A
)
如果我写:disp("There are "),disp(A),disp(" horses.")
我得到:
There are
5
horses.
但我希望所有内容都在一行中。
我该怎么做?
最佳答案
您可以使用:
A = 5
printf("There are %d horses\n", A)
输出:
There are 5 horses
甚至
disp(["There are ", num2str(A), " horses"])
甚至
disp(strcat("There are ", num2str(A), " horses"))
但是你必须添加一些东西,因为 Octave /matlab 不允许字符串末尾的空格,所以输出是:
ans = There are5 horses
关于console - 将文本输出到 Octave 控制台,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15266535/