Filter löschen
Filter löschen

Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

Getting matlab to automatically produce graphs and the save them

2 Ansichten (letzte 30 Tage)
Callum Swann
Callum Swann am 28 Apr. 2020
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
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?

Antworten (1)

Ameer Hamza
Ameer Hamza am 28 Apr. 2020
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

Diese Frage ist geschlossen.

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by