Trying to print 2 different variables using fprintf.
34 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Shawn
el 6 de Feb. de 2014
Respondida: Walter Roberson
el 6 de Feb. de 2014
I have 2 matrix, a=[1 2 3;4 5 6;n n n] and b=[11 22 33;44 55 66;nn nn nn] I am trying to print the 1st variable of a and b then the next etc:
fprintf('A is %6.4f and b is %6.4f', a, b);
the way math lab is working gives an output of:
A is 1 and b is 2
A is 3 and b is 11
A is 22 and b is 33
How can i separate it so it shows
A is 1 and b is 11
A is 2 and b is 22
A is 3 and b is 33
A is n and b is nn
0 comentarios
Respuesta aceptada
Walter Roberson
el 6 de Feb. de 2014
fprintf('A is %6.4f and b is %6.4f', [a(:), b(:)].' );
Note: this will not print in the order you indicated because in MATLAB, the second variable of "a" is the 4, not the 2. If you want to print across the rows instead of down the columns, then
fprintf('A is %6.4f and b is %6.4f', permute(cat(3,a,b), [3 2 1]));
and the first version, taking the values in column order, can be done as
fprintf('A is %6.4f and b is %6.4f', permute(cat(3,a,b), [3 1 2]));
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Spreadsheets en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!