how can I display 3 row vectors as column vectors in front of eachother using fprintf?

7 views (last 30 days)
I have 3 row vectors with same size
i would like to show this vectors in form of a column vector and i want them to be in front of eachother using fprintf command
like this:
input:
a=[1 2 3]
b=[11 22 33]
c=[111 222 333]
output:
1 11 111
2 22 222
3 33 333

Accepted Answer

Stephen23
Stephen23 on 6 Jan 2021
a = [1,2,3];
b = [11,22,33];
c = [111,222,333];
fprintf('%d %d %d\n',[a;b;c])
1 11 111 2 22 222 3 33 333

More Answers (1)

Rik
Rik on 6 Jan 2021
Just use a loop:
a=[1 2 3];
b=[11 22 33];
c=[111 222 333];
for n=1:numel(a)
fprintf('%d %d %d\n',a(n),b(n),c(n))
end
  3 Comments
Rik
Rik on 6 Jan 2021
Since it is easy to confuse printed lines with matrix rows, I personally prefer a loop when using array inputs. That way it is impossible to make a mistake. One of the tables in my master thesis was flipped in the print version because of this (which was extra unfortunate, as it was a 3x4 table, making the interpretation of the results a mystery).

Sign in to comment.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!