copy contents of file with variable number in Matlab

input : transient.case

output: transient_1.case, transient_2.case, transient_3.case ...

************transient.case

FORMAT
type: ensight gold
GEOMETRY
model: solution.pval.unsteady_1.geo
VARIABLE
scalar per node: density   solution.pval.unsteady_*.density
vector per node: v   solution.pval.unsteady_*.v
scalar per node: pressure   solution.pval.unsteady_*.pressure
scalar per node: temperature   solution.pval.unsteady_*.temperature
TIME
time set: 1
number of steps: 1
filename start number:2
filename increment: 1
time values: 1.0319174484984 1.8385297551528

*******************

where, filename start number:2, 

is the same as filename

 

**************************code.m

n=10;
fileinfo = importdata('transient.case',';');
for i=1:n
filename=sprintf('transient_%d.case',i);
a=cell2mat(fileinfo(13));
idx=find(a==':');
fileinfo(13)=cellstr(strrep(a,a(idx+1:end),num2str(i)));
filePh = fopen(filename,'w');
fprintf(filePh,'%s\n',fileinfo{:});
fclose(filePh);
end
*****************

 

posted @ 2019-02-22 15:03  kaiming_ai  阅读(133)  评论(0编辑  收藏  举报