MATLAB: Fprinf format

fopenformatfprintf

hi, i have this problem, suppose i have
x=[1,2,3]
y=[4,5,6]
z=[7,8,9]
i had it save use "fid=fopen" and "fprintf" command to "results.str", how to make the results.str saved in this following format:
s
100
1
7 1 4
8 2 5
9 3 6
which "s" 100 and 1 is a constant value to begin with, followed by z in the first column, then x and y.
anyone can help?

Best Answer

x=[1,2,3]
y=[4,5,6]
z=[7,8,9]
FileName='results';
FID = fopen(FileName, 'w');
if FID < 0, error('Cannot open file'); end
data = [z', x', y'];
fprintf(FID, 's\n%g\n%g\n', 100,1);
fprintf(FID, '%g %g %g\n', data');
fclose(FID);