Trying to print 2 different variables using fprintf.
33 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Walter Roberson
2014-2-6
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!