MATLAB: How to save multiplfe for loop output in differnt columns of txt file

for loopMATLABsave

Hi I want to save for loop outputs in different columns of txt file. Below is an example
C{1}=[562
556
554
552
552
552
550
550
554
554
]
C{2}=[554
572
572
576
576
590
584
584
596
596
]
fileID=('ans.txt');
fid=fopen(fileID,'w');
for j=1:2
for i=1:9
H(i)=C{j}(i)+C{j}(i+1)
fprintf(fid, '%f \n', H(i));
end
end
Then I've got the .txt file written as
1118.000000
1110.000000
1106.000000
1104.000000
1104.000000
1102.000000
1100.000000
1104.000000
1108.000000
1126.000000
1144.000000
1148.000000
1152.000000
1166.000000
1174.000000
1168.000000
1180.000000
1192.000000
I want the output written in two separate columns (9 x 2). How can I do to get that format? Thank you.

Best Answer

for j=1:2
for i=1:9
H(j, i)=C{j}(i)+C{j}(i+1)
end
end
fprintf(fid, '%10f %10f\n', H);