how to print matrix with fprintf

8 visualizaciones (últimos 30 días)
Taehun Kim
Taehun Kim el 3 de Sept. de 2017
Respondida: Walter Roberson el 3 de Sept. de 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

Respuestas (1)

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

Categorías

Más información sobre Workspace Variables and MAT-Files en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by