MATLAB: Printing columns next to each other

arrays array fprinf print

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

Best Answer

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]')