MATLAB: Fprrintf MATLAB R2013a not working

fprintftxt file

Hey everyone,
I'm sending my values to a txt file in MATLAB R2013a but the txt file remains empty and all the printing is done in the command window! Does anyone know why is this happening? And how can I print the values in a txt file?
fid = fopen('Code.txt','w');
fprintf('start a new cycle \n');
fprintf('t = %0.5f\t total_diss %0.5f\n', t, total_diss)
fclose(fid);

Best Answer

Yasmine, use
fid = fopen('Code.txt','w');
fprintf(fid,'start a new cycle \n');
fprintf(fid,'t = %0.5f\t total_diss %0.5f\n', t, total_diss)
fclose(fid);
instead. Note that you need to add the fileID fid to the fprintf command.