Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
Getting matlab to automatically produce graphs and the save them
조회 수: 1 (최근 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?
댓글 수: 0
답변 (1개)
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
댓글 수: 0
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!