how to print matrix with fprintf

Hi all i want to ask how to print a matrix A below with fprintf function with %4d conversion specifier
A =
1 1 -1 1 1 -1 -1 1 1 1 -1 1
1 -1 1 -1 -1 1 1 1 1 -1 1 1
1 1 1 -1 1 -1 1 -1 -1 -1 -1 1
1 -1 1 -1 -1 -1 1 1 -1 -1 -1 1
1 1 -1 1 1 -1 -1 -1 1 -1 1 -1
1 -1 1 1 1 1 1 -1 -1 -1 1 -1

回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 9 月 3 日

1 投票

fmt = [repmat('%4d ', 1, size(A,2)-1), '%4d\n'];
fprintf(fmt, A.'); %transpose is important!

カテゴリ

ヘルプ センター および File ExchangeAerospace Blockset についてさらに検索

タグ

質問済み:

2017 年 9 月 3 日

回答済み:

2017 年 9 月 3 日

Community Treasure Hunt

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

Start Hunting!

Translated by