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

7 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Stephen23
Stephen23 il 6 Gen 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

Più risposte (1)

Rik
Rik il 6 Gen 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 Commenti
Rik
Rik il 6 Gen 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).

Accedi per commentare.

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by