MATLAB Answers

Writing a Script..

1 ビュー (過去 30 日間)
FG
FG 2020 年 9 月 7 日
コメント済み: FG 2020 年 9 月 7 日
Hi all.. I have a bunch of mat files consisting of 25 types data each inside. I am interested in only 4 of them. They also are in another directory different than matlab. What I want to do is reading only all 4 data from all mat files. How can I write a script for this.. Thnx

  2 件のコメント

KSSV
KSSV 2020 年 9 月 7 日
What data to be read from each mat file?
FG
FG 2020 年 9 月 7 日
Harmonics for example.. 3,5,7 and thd

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

採用された回答

Stephen Cobeldick
Stephen Cobeldick 2020 年 9 月 7 日
D = 'absolute or relative path to the folder file where the files are saved';
S = dir(fullfile(D,'Case*.mat'));
N = numel(S);
C = cell(1,N);
for k = 1:N
% change 'f1' etc. to the names of the data you want:
T = load(fullfile(D,S(k).name),'f1','f2','f3','f4');
S(k).f1 = T.f1;
S(k).f2 = T.f2;
S(k).f3 = T.f3;
S(k).f4 = T.f4;
end
It will import the required file data into the structure S:

  3 件のコメント

FG
FG 2020 年 9 月 7 日
S = dir(fullfile(D,'Case*.mat')); is it going to read case1111, case1112, case1113.. etc. automatically ? And what s gonna be the name here..?
T = load(fullfile(D,S(k).name)
Thank you..
Stephen Cobeldick
Stephen Cobeldick 2020 年 9 月 7 日
"is it going to read case1111, case1112, case1113.. etc. automatically ?"
Yes.
"And what is gonna be the name here..?"
name is one the fields in the structure returned by dir, the field contains the filenames. To know more read the dir documentation and the link that I gave you
FG
FG 2020 年 9 月 7 日
Thnx for your help.. Thnx indeed

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

その他の回答 (0 件)

製品

Community Treasure Hunt

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

Start Hunting!

Translated by