How to modify few numbers in a random text file?
1 次查看(过去 30 天)
显示 更早的评论
I am uploading a text file related to a model in an electronic simulator. How to modify the 4 parameters named with
toxe = %1.1d
toxp = %1.1d
toxm = %1.1d
vth0 = %1.1d
If this text file didn't have format specifier, I would just write this file using
model = fileread(fullfile(pathname_model,filename_model));
File_model = fopen(fullfile(dirname,filename_model),'w');
fprintf(File_model,'%s',model);
fclose(File_model);
Since now I want to modify a few parameters each time I run my code, I edited the text file and put format specifier but I don't know how can I print the modified file now.
Is this correct?
model = fileread(fullfile(pathname_model,filename_model));
File_model = fopen(fullfile(dirname,filename_model),'w');
fprintf(File_model,'%s',model, par1, par2, par3, par4);
fclose(File_model);
where par1 to par4 are the first 4 parameter values that I listed at the top.
0 个评论
采纳的回答
per isakson
2021-2-5
编辑:per isakson
2021-2-5
Try this
%%
chr = fileread('model_v2.txt');
ffs = 'model_out.txt';
fid = fopen( ffs, 'w' );
[~] = fprintf( fid, chr, 1.2, 3.4, 5.6, 7.8 );
[~] = fclose( fid );
I've changed the format specs in the file, model_v2.txt, to %3.1f because I assume that's what you intended.
Line 8 of model_out.txt now looks like
+tnom = 27 toxe = 1.2 toxp = 3.4 toxm = 5.6
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!