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

조회 수: 3 (최근 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에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by