gpt4 book ai didi

console - 将文本输出到 Octave 控制台

转载 作者:行者123 更新时间:2023-12-04 10:04:39 30 4
gpt4 key购买 nike

假设我有一个变量 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/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com