how can I display 3 row vectors as column vectors in front of eachother using fprintf?
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Aref Mirjalili
il 6 Gen 2021
Commentato: madhan ravi
il 6 Gen 2021
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
0 Commenti
Risposta accettata
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])
0 Commenti
Più risposte (1)
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
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).
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!