How to create .png files having same file name as the .dat file from which I'm writing the code?
3 views (last 30 days)
Show older comments
Arghadwip Paul
on 22 May 2017
Commented: Arghadwip Paul
on 23 May 2017
I'm having .dat files having name t-0.dat,t-1.dat,t-2.dat,t-4.dat,t-16.dat,.....t-100000.dat. I want to make .png files with the same names i.e. t-0.png,t-1.png,t-2.png,.....How do I do it?
Here is my code. Here I could create files with name- fig1.png,fig2.png,fig3.png,fig4.png.(fig1 corresponding to t-0.dat, like this. But I want to name it t-0.png or fig1.png).
myfolder= '........../datafolder';
datfiles = dir('*.dat');
for k = 1 : length(datfiles)
baseFilename= datfiles(k).name;
data = load(datfiles(k).name);
fullFilename= fullfile(myfolder, baseFilename);
fprintf(1, 'Now reading %s\n', fullFilename);
h=figure;
scatter(data(:,1),data(:,2),50);
hold on;
quiver(data(:,1),data(:,2),data(:,4),data(:,5),0.3);
saveas(h,sprintf('fig%d.png',k));
hold off;
end
0 Comments
Accepted Answer
More Answers (0)
See Also
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!