How to concatenate multiple mat files into a single cell array

5 ビュー (過去 30 日間)
Abdulhakim Alezzi
Abdulhakim Alezzi 2021 年 3 月 30 日
回答済み: Shubham Khatri 2021 年 4 月 9 日
Dear Friends
I have 22 different matfiles with (C1,C2,C3,...C22). All these files have a same name (data).
I want to concatenate all these files into a single cell array.
I have tried this code, but it does not help.
D = 'path to the folder where the files are saved'
S = dir(fullfile(D,'C*.mat'));
C = cell(1,numel(S));
Z = load(fullfile(D,S(1).name));
F = fieldnames(T);
for k = 2:numel(S)
T = load(fullfile(D,S(k).name));
for n = 1:numel(F)
Z.(F{n}) = cat(1, Z.(F{n}), T.(F{n}));
end
end
save(fullfile(D,'Y.mat'),'Z')
....
Any help will be highly appreciated .
  1 件のコメント
Adam Danz
Adam Danz 2021 年 3 月 30 日
Focus in on the problem by explicitly describing/showing the problem rather than "it does not help". Are you having trouble selecting the right files (ie, problems with dir/load etc)? Are you having trouble with concatenation? Is there an error message (if so, share all of it). Then give some more information about the the variables in the line that is causing the problem.
The idea is to reduce the guess-work needed on our end and to make is super easy for use to quickly identify the problem.

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

採用された回答

Shubham Khatri
Shubham Khatri 2021 年 4 月 9 日
Hello,
Please refer to this Answer on the community to automate the file loading procedure. For more information on using cat, please refer to this documentation link here.
Hope it helps

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDebugging and Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by