Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试将多个变量与随附的文本一起打印到命令窗口。disp 似乎不想工作,fprintf 也不想工作。有谁知道我怎么能做到这一点。我正在尝试打印代码如下所示,在文本之间插入变量
print('The minimum value is', minY1(2), 'which occurs at x = ', minX);
例如,这将导致
最小值为 69.054,出现在 x = 5
干杯
尝试这个:
fprintf('The minimum value is %d which occurs at x = %d', minY1(2), minX);
%d用于数字并将%s用于字符串。
%d
%s
disp 可能没有产生您想要的结果,因为您需要将数字显式转换为文本。你可以试试:
disp(['The minimum value is ' num2str(minY1(2)) ', which occurs at x = ' num2str(minX)]);