MATLAB: Problem using fprintf for writing celldata into world.

fprintf

v =
[ 1] [ 0.005414061590159] [-0.089918561343438]
'p2' [-0.055125605058493] [ 0.077283840482778]
'p3' [ 0.041872392912978] [ 0.048029359618340]
%class is cell
%I perform to write v into ms word like that,
for k=1:size(v,1)
fprintf(fileID, '%3s %40f %3f \n', v{k,:});
end
%It cannot write "1" into world. (others appears) How can I write v with full of first column?

Best Answer

for k=1:size(v,1)
if ischar(v{k,1})
fprintf(fileID, '%3s %40f %3f \n', v{k,:});
else
fprintf(fileID, '%3d %40f %3f \n', v{k,:});
end
end