MATLAB: How to use %d to get a column of numbers in %d format

d

Hi, I have the following code, but it isn't working:
x=0.05:0.001:0.25;
for i=1:201
data(i,1) = ('%d',i);
end
for i=1:201
data(i,2) = x(i);
end
save 'data.dat' data -ascii;
I want 201 rows of data, where the first column contains 1 2 3 … (in %d format) while the second column contains values of x in %e format. How can I do this?
Thank you very much in advance!

Best Answer

x=0.05:0.001:0.25;
for i=1:201
data{i,1} = sprintf('%d',i);
end
for i=1:201
data{i,2} = sprintf('%e', x(i));
end
However, this creates cell arrays of character vectors, and those cannot be saved using save -ascii .
You would be better off going for writing them yourself:
fid = fopen('data.dat', 'wt');
fprintf( fid, '%3d %e\n', [1:201; x]);
fclose(fid)