How to create .png files having same file name as the .dat file from which I'm writing the code?

2 次查看(过去 30 天)
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

采纳的回答

Stephen23
Stephen23 2017-5-22
编辑:Stephen23 2017-5-22
[fpth,fnm] = fileparts(original_name);
new_name = fullfile(fpth,[fnm,'.png']);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Printing and Saving 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by