Info

此问题已关闭。 请重新打开它进行编辑或回答。

Getting matlab to automatically produce graphs and the save them

2 次查看(过去 30 天)
I am new to Matlab so apologies if this seems simple.
I have a task where I have a number of folders containing .mat files and these files contain matrices.
I have folders 'test1' through to 'test50'. each folder contains 2 .mat files 'velocitydata.mat' and 'aerodynamicdata.mat'. Each .mat file has 3 matrices in the workspace Velocity,x,y,z and force,x,y,z.
I want to produce graphs for each folder showing plots of velocity in x over time and then save them in the relevant folder automatically. So for instance folder 'test1' will contain all the .mat files and the relevant .png graphs.
Is there anyway I can do this?

回答(1 个)

Ameer Hamza
Ameer Hamza 2020-4-28
Try something like this
files = dir('*/velocitydata.mat');
for i=1:numel(files)
filename = fullfile(files(i).folder, files(i).name);
l = load(filename);
plot(l.velocity_x);
[~, name] = fileparts(filename);
save_filename = fullfile(files(i).folder, [name, '.png']);
print(save_filename, '-r300'); % 300 ppi resolution
end

此问题已关闭。

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by