フィルターのクリア

Matlab tool to extract data from struct to seperate .mat files

3 ビュー (過去 30 日間)
Henning Schmitz
Henning Schmitz 2022 年 12 月 28 日
コメント済み: Henning Schmitz 2023 年 1 月 2 日
Hello together,
i want to build a tool (best case a GUI) where you can load in data (.mat struct files) and extract the different values to seperate .mat files which then can be saved as new .mat files.
I don't know the names of the variables in the struct.
Would be very nice to get some help from you guys, thanks!
  8 件のコメント
Stephen23
Stephen23 2023 年 1 月 2 日
As Jan wrote, LOAD the MAT-file and loops over its content using FIELDNAMES():
S = load('rec1_002.mat')
S = struct with fields:
Info: [1×1 struct] X: [1×1 struct]
A = struct2cell(S);
B = fieldnames(S);
for k = 1:numel(A)
T = cell2struct(A(k),B(k));
F = sprintf('%s.mat',B{k});
save(F,'-struct','T')
end
Checking:
dir *.mat
Info.mat X.mat rec1_002.mat
You can modify this to select only the MAT file that the user wants, etc.
Henning Schmitz
Henning Schmitz 2023 年 1 月 2 日
Thank you that helps a lot!

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeWorkspace Variables and MAT-Files についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by