how to print matrix with fprintf

10 Ansichten (letzte 30 Tage)
Taehun Kim
Taehun Kim am 3 Sep. 2017
Beantwortet: Walter Roberson am 3 Sep. 2017
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

Antworten (1)

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

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by