How to read all mat files in folder and save plot as image

10 ビュー (過去 30 日間)
Med Future
Med Future 2022 年 6 月 2 日
回答済み: Image Analyst 2022 年 6 月 2 日
Hello everyone, i hope you are doing well. i have the following 100 .mat files in folders.
i want to save the plot of all .mat files as image.
I have implement the following code for single mat file
S = load('C:\Users\DELL\Documents\MATLAB\Examples\R2021b\deeplearning_shared\ModulationClassificationWithDeepLearningExample\Dataset1\frame8PSK001.mat');
plot(real(S.frame))
set(gca,'visible','off')
  2 件のコメント
Stephen23
Stephen23 2022 年 6 月 2 日
What is your question?
Med Future
Med Future 2022 年 6 月 2 日
@Stephen23 i want to read all mat files from folder then plot real of the mat file and saves the plot as images as i done for one file in above code

サインインしてコメントする。

採用された回答

Mathieu NOE
Mathieu NOE 2022 年 6 月 2 日
hello
you can try / build your solution based on this example
here I wanted all data being in one single plot so I concatenated all the files data in one output array. You can of course avoid this step and plot individually each file and save it
fileDir = pwd; % this directory
fileNames = dir(fullfile(fileDir,'frame*.mat')); % get list of data files in directory
fileNames_sorted = natsortfiles({fileNames.name}); % sort file names into natural order
% (download FEX : https://fr.mathworks.com/matlabcentral/fileexchange/47434-natural-order-filename-sort)
M= length (fileNames_sorted);
time1 = [];
signal1 = [];
for f = 1:M
S = load(fullfile(fileDir, fileNames_sorted{f}))
% contatenation of all individual files data
time1 = [time1; S.ScopeData1.time];
signal1 = [signal1; S.ScopeData1.signals.values];
end
figure
plot(time1,signal1,'*-')
% save plot
print('MySavedPlot','-dpng')

その他の回答 (1 件)

Image Analyst
Image Analyst 2022 年 6 月 2 日
To save the plot you can use exportgraphics:
fileName = fullfile(folder, 'frame8PSK001.png');
exportgraphics(gca, fileName);

カテゴリ

Help Center および File ExchangePrinting and Saving についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by