What is the code to plot several .dat files together?

I have 1000 .dat files and I want to plot graphs from them and save the results in .png format for all the files. How do we do that?

1 个评论

I have the same question.
The answer down here are not working for me.
@KSSV

请先登录,再进行评论。

 采纳的回答

figure
hold on
datfiles = dir('*.dat');
for K = 1 : length(datfiles)
data = load(datfiles(k).name); %load just this file
% Plot the data depending on variables
end

6 个评论

Thanks. But, I want to store all the plots in .png format and then make an animation of how the system is evolving with time.
I am working on Molecular dynamics simulations. So I have 10000 .dat files which shows the state of the system at different instants and I want to generate a plot of these files and make an animation out of them.
can you please help me how to sort all the files? My file names are t-0.dat, t-1.dat,t-2.dat,t-4.dat,...t-16.dat,...., t-128.dat,........t-10000.dat. But when I'm using the code to plot the results, it reads t-0, t-1,t-128,t-10000, then t-2,....t-4... like this. I want to get them in order. How do I do it? (I have modified your code a bit to get the plots).
datfiles1 = dir('*.dat');
for k = 1 : length(datfiles)
data = load(datfiles(k).name);
h=figure;
scatter(data(:,1),data(:,2),50);
hold on;
quiver(data(:,1),data(:,2),data(:,4),data(:,5),0.3);
end
saveas(h,sprintf('fig%d.png',k));
hold off;
end
Thanks. But, I have already tried using natsortfiles,it did not work. I could not apply it properly as I'm new into Matlab. Can you please help me regarding how I should apply natsortfile function here to sort the files?
datfiles = dir('*.dat');
for k = 1 : length(datfiles)
data = load(datfiles(k).name);
h=figure;
scatter(data(:,1),data(:,2),50);
hold on;
quiver(data(:,1),data(:,2),data(:,4),data(:,5),0.3);
end
saveas(h,sprintf('fig%d.png',k));
hold off;
end

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Line Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by