printing columns next to each other

14 vues (au cours des 30 derniers jours)
Rashid Hussein
Rashid Hussein le 19 Nov 2017
Commenté : Sara Pierson le 1 Avr 2021
i have 4 arrays
a=[1;2;3] b=[4;5;6] c=[7;8;9] d=[10;11;12]
fileid=fopen('saving.txt','w'); fprintf(fileid,'%6s %12s %14s %16s\r\n','Enrgy','countrate','FWHM','Resolution');
fprintf(fileid,'%6.4f %12.4f %14f %16f\n',a, b,c,d); i want to print each column next to each other like:
1 4 7 10
2 5 8 11
3 5 9 12
but i showed like this
Enrgy countrate FWHM Resolution
1.0000 2.0000 3.000000 4.000000
5.0000 6.0000 7.000000 8.000000
9.0000 10.0000 11.000000 12.000000
so please any help

Réponse acceptée

Star Strider
Star Strider le 19 Nov 2017
You need to concatenate the variables into a matrix, then transpose the matrix:
fprintf(fileid, '%6.4f %12.4f %14f %16f\n',[a,b,c,d]')
  1 commentaire
Sara Pierson
Sara Pierson le 1 Avr 2021
That does not work matlab 2020b unfortunately

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by