I\'m new to matlab and I need some help. I want to re-use three columns from a txt file and add two extra ones created by me.
My .txt file is:
The major thing which was making the fprintf
fail was your %n
in the format specifier. In matlab use a %d
instead.
slightly rewriting your last loop with a modified format specifier will produce the desired output:
%% // write new file
fileout = 'imc_out.txt' ;
fid=fopen(fileout,'wt');
for i=1:length(imc)
fprintf(fid,'%s %d %3.2f %3.1f %s\n',nome{i},peso(i),altura(i),imc(i),imc_ok{i}) ;
end
fclose(fid)