Trying to print 2 different variables using fprintf.
33 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Shawn
am 6 Feb. 2014
Beantwortet: Walter Roberson
am 6 Feb. 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 Kommentare
Akzeptierte Antwort
Walter Roberson
am 6 Feb. 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Spreadsheets finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!