フィルターのクリア

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 Center および File ExchangePrinting and Saving についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by