Borrar filtros
Borrar filtros

Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Getting matlab to automatically produce graphs and the save them

2 visualizaciones (últimos 30 días)
Callum Swann
Callum Swann el 28 de Abr. de 2020
Cerrada: MATLAB Answer Bot el 20 de Ag. de 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?

Respuestas (1)

Ameer Hamza
Ameer Hamza el 28 de Abr. de 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

La pregunta está cerrada.

Etiquetas

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by