Clear Filters
Clear Filters

Change file name in loop

4 views (last 30 days)
Krish Desai
Krish Desai on 25 Mar 2016
Commented: Krish Desai on 25 Mar 2016
For some reason only one file dump_0 is being created. Does this mean Matlab is not going through the for loop?
for t=0:dt:4*dt %99 for 100 graphs
figure;
for ind=1:1920
U=(3*ind+linspace(1,3,3)-3);
Phi= PHI_disp_RBME_ModePlot_N(U);
r=xlocs_full(ind);
omega=(f_disp_RBME(iMode,kPtMode)*2*pi);
k=kappa_space(kPtMode);
spatialphase=k*r;
timephase=omega*t;
displ=Phi*exp(i*((spatialphase)-(timephase)));
xOvito(ind)=xOvito(ind)+magFact*displ(1);
yOvito(ind)=yOvito(ind)+magFact*displ(2);
zOvito(ind)=zOvito(ind)+magFact*displ(3);
header1= 'id';
header2= 'type';
header3='x';
header4='y';
header5='z';
k=0;
fileName='Dump_';
fid=fopen([fileName,num2str(k)],'w');
fprintf(fid, [ header1 ' ' header2 ' ' header3 ' ' header4 ' ' header5 '\n']);
fprintf(fid, '%f %f %f \n', [xOvito yOvito zOvito]');
fclose(fid);
k=k+1;
...
end

Answers (1)

Walter Roberson
Walter Roberson on 25 Mar 2016
You have
k=0;
inside the loop, so you are resetting the name each time.
  1 Comment
Krish Desai
Krish Desai on 25 Mar 2016
I put it outside all the loops, at the top, I still only got one file: dump_0.040673

Sign in to comment.

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!