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

9 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Stephen23
Stephen23 am 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

Weitere Antworten (1)

Rik
Rik am 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 Kommentare
Rik
Rik am 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).

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by