Appending data in multiple structures using a loop

11 ビュー (過去 30 日間)
Binu
Binu 2021 年 2 月 11 日
回答済み: Stephen23 2021 年 2 月 17 日
Hi all,
I have three *.mat files as shown under the Current Folder space in the image. Each mat file has two structures named Config and Waves_Data as shown in the Workspace. Under the Waves_Data, there are several Fields as shown in Variables section. I need to extract Time and Status_ Amplitude fields from each *.mat file and append them one after the other to have a combined Time and combined Status_Amplitude.
How can I put these into a loop. Appreciate your thoughts.
Thank you

回答 (1 件)

Stephen23
Stephen23 2021 年 2 月 17 日
D = 'absolute/relative path to where the files are saved';
S = dir(fullfile(D,'*.mat'));
N = numel(S);
for k = 1:N
F = fullfile(D,S(k).name);
T = load(F);
S(k).Time = T.Waves_Data.Time;
S(k).StAm = T.Waves_Data.Status_Amplitude;
end
Time = horzcat(S.Time) % or VERTCAT
StAm = horzcat(S.StAm) % or VERTCAT

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by