Adding new columns to a text file on matlab

前端 未结 1 1710
挽巷
挽巷 2021-01-27 10:39

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:

相关标签:
1条回答
  • 2021-01-27 11:25

    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)
    
    0 讨论(0)
提交回复
热议问题