Loading Data from multiple .mat files in a folder and plotting

I need to load data from these 10 .mat files and plot fx versus Uref. Can anyone please help me with a sample code. I have tried using the for loop but it's not loading all the files.

6 件のコメント

Rik
Rik 2023 年 5 月 12 日
If you show your code, it will be easier to suggest edits. It sounds like you are almost there already.
Imtiaz
Imtiaz 2023 年 5 月 12 日
Hi. Here's my code. As you can see I am only able to select one .mat file from this folder. And when I look at the workspace it also shows data only from one folder.
Walter Roberson
Walter Roberson 2023 年 5 月 12 日
The code did not get posted?
Rik
Rik 2023 年 5 月 12 日
Also, please do not post a picture of your code, but post the code itself.
Stephen23
Stephen23 2023 年 5 月 31 日
編集済み: Stephen23 2023 年 5 月 31 日
The simple and efficient approach is to let DIR get the filenames, e.g.:
P = 'absolute/relative path to where the files are saved';
S = dir(fullfile(P,'OCTAGON*.mat'));
for k = 1:numel(S)
F = fullfile(S(k).folder,S(k).name);
D = load(F)
..
end

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

回答 (1 件)

Swaraj
Swaraj 2023 年 5 月 31 日

0 投票

Hi Imtiaz,
I understand that you want to load multiple .mat file from a folder and plot the data from it and you are facing problem in loading the .mat files.
To check your issue, I created a folder with following files.
I wrote the following sample code, and I was able to load the specified three .mat file and ignoring the excel file.
currentDir = pwd;
fileList = dir(currentDir);
fileList = {fileList.name};
filteredFileList = fileList(cellfun(@(x) contains(x, 'OCTAGON') && contains(x,'.mat'), fileList));
for i=1:length(filteredFileList)
file = load(filteredFileList{i});
%Do your task with the file here
end
This is just the sample code. You can rewrite it as per your requirements.
Hope it helps!!

カテゴリ

ヘルプ センター および File ExchangeDebugging and Analysis についてさらに検索

製品

リリース

R2023a

質問済み:

2023 年 5 月 12 日

編集済み:

2023 年 5 月 31 日

Community Treasure Hunt

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

Start Hunting!

Translated by