trouble printing string and matrix using fprintf
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
so I have a 20x1 string which is
B=[Alanine Arginine Asparagine Aspartic Cysteine Glutamic Glutamine Glycine Histidine Isoleucine Leucine Lysine Methionine Phenylanlanine Proline Serine Threonine Tryptophan Tyrosine Valine]
which was original a cell that was taken from an excel file and I have a 1x20 matrix which is
Z=[ 89.0941 175.2109 132.1192 132.0960 121.1601 146.1229 146.1461 75.0672 156.1644 131.1748 131.1748 147.1974 149.2139 165.1919 116.1399 105.0935 119.1204 203.2206 469.7853 117.1479]
. Im supposed to display both of them side by side to one another vertically so one column is the B and the second column Z. When is use frpintf I cant get it to display properly. I use
fprintf('%s %f\n', B, Z);
to display them but everytime I use it I get
Alanine NaN
Asparagine NaN
Cysteine NaN
Glutamine NaN
Histidine NaN
Leucine NaN
Methionine NaN
Proline NaN
Threonine NaN
Tyrosine NaN
8.909412e+01 175.210860
1.321192e+02 132.095980
1.211601e+02 146.122860
1.461461e+02 75.067240
1.561644e+02 131.174760
1.311748e+02 147.197380
1.492139e+02 165.191880
1.161399e+02 105.093520
1.191204e+02 203.220620
4.697853e+02 117.147880
When I run the string and the matrix seperately using fprintf they display properly. How can I display them side by side properly?
0 Commenti
Risposte (1)
Walter Roberson
il 11 Dic 2020
See topical discussion at
temp = [cellstr(B(:)), num2cell(Z(:))];
fprintf('%s %f\n', temp{:});
0 Commenti
Vedere anche
Categorie
Scopri di più su Cell Arrays 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!