如何在Matlab中显示(打印)矢量? [英] How to display (print) vector in Matlab?
本文介绍了如何在Matlab中显示(打印)矢量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个向量x = (1, 2, 3)
,我想将其显示(打印)为Answer: (1, 2, 3)
.
I have a vector x = (1, 2, 3)
and I want to display (print) it as Answer: (1, 2, 3)
.
我尝试了许多方法,包括:
I have tried many approaches, including:
disp('Answer: ')
strtrim(sprintf('%f ', x))
但是我仍然无法以我需要的格式打印它.
But I still can't get it to print in format which I need.
请问有人指出我的解决方案吗?
Could someone point me to the solution, please?
值和x
的长度都未知.
Both the values and (length of) x
are not known in advance.
推荐答案
我更喜欢以下内容,它更干净:
I prefer the following, which is cleaner:
x = [1, 2, 3];
g=sprintf('%d ', x);
fprintf('Answer: %s\n', g)
输出
Answer: 1 2 3
这篇关于如何在Matlab中显示(打印)矢量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文