how to print matrix with fprintf
8 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Walter Roberson
on 3 Sep 2017
fmt = [repmat('%4d ', 1, size(A,2)-1), '%4d\n'];
fprintf(fmt, A.'); %transpose is important!
0 Comments
See Also
Categories
Find more on Workspace Variables and MAT-Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!