Using fprintf for matrix
701 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I have a matrix with 300 rows and 2 columns. For instance:
1 2
2 4
5 6
and another matrix with 300 rows and 1 column: for instance:
1
3
4
I want to convert them in the following:
-1: 1 2
-3: 2 4
-4: 5 6
It would be appreciated if you could help me. Thanks
0 Commenti
Risposta accettata
Stephen23
il 30 Mag 2016
Modificato: Stephen23
il 30 Mag 2016
>> X = [1,2;2,4;5,6];
>> Y = [1;3;4];
>> fprintf('-%d: %d %d\n', [Y,X].')
-1: 1 2
-3: 2 4
-4: 5 6
It is worth reading the fprintf documentation carefully, to see how it handles matrices (columnwise!) and to pick the best format string for your requirements.
Più risposte (1)
Ambrish Raghav
il 30 Lug 2020
X = [1,2;2,4;5,6];
>> Y = [1;3;4];
>> fprintf('-%d: %d %d\n', [Y,X].')
-1: 1 2
-3: 2 4
-4: 5 6
0 Commenti
Vedere anche
Categorie
Scopri di più su Environment and Settings 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!