how can I display 3 row vectors as column vectors in front of eachother using fprintf?

7 ビュー (過去 30 日間)
I have 3 row vectors with same size
i would like to show this vectors in form of a column vector and i want them to be in front of eachother using fprintf command
like this:
input:
a=[1 2 3]
b=[11 22 33]
c=[111 222 333]
output:
1 11 111
2 22 222
3 33 333

採用された回答

Stephen23
Stephen23 2021 年 1 月 6 日
a = [1,2,3];
b = [11,22,33];
c = [111,222,333];
fprintf('%d %d %d\n',[a;b;c])
1 11 111 2 22 222 3 33 333

その他の回答 (1 件)

Rik
Rik 2021 年 1 月 6 日
Just use a loop:
a=[1 2 3];
b=[11 22 33];
c=[111 222 333];
for n=1:numel(a)
fprintf('%d %d %d\n',a(n),b(n),c(n))
end
  3 件のコメント
Rik
Rik 2021 年 1 月 6 日
Since it is easy to confuse printed lines with matrix rows, I personally prefer a loop when using array inputs. That way it is impossible to make a mistake. One of the tables in my master thesis was flipped in the print version because of this (which was extra unfortunate, as it was a 3x4 table, making the interpretation of the results a mystery).

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by