フィルターのクリア

How to combine the elements of several identical cell structure ?

1 回表示 (過去 30 日間)
Salaijobhaka
Salaijobhaka 2016 年 10 月 3 日
コメント済み: Salaijobhaka 2016 年 10 月 4 日
I have 100 .mat files each containing a cell structure "Tau" with components "Tau.n" and "Tau.u", each component is an array of size 1000*5*11.
I would like to combine the data from all these .mat files such that we could generate one .mat file that now has a cell structure "Tau" with components "Tau.n" and "Tau.u" of size 100000*5*11
What would be the easiest way to do this ? For eaxample I have attached four .mat files. In this case the cell components "Tau.u" and "Tau.n" each becomes an array of size 4000*5*11.
  2 件のコメント
Joe Yeh
Joe Yeh 2016 年 10 月 3 日
The data contained in the mat file does not match your description. Can you update either your question or the mat files ?
Salaijobhaka
Salaijobhaka 2016 年 10 月 3 日
Thank you for the response. I have updated the question now !!

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

採用された回答

Joe Yeh
Joe Yeh 2016 年 10 月 3 日
編集済み: Joe Yeh 2016 年 10 月 3 日
Ok. Here's a solution for you :
Tau = struct;
for ii = 0:9
data = load(['Tau@09_n1000_c', num2str(ii), '.mat']);
if ii == 0
Tau.u = data.Tau.u;
Tau.n = data.Tau.n;
else
Tau.u = cat(4, data.Tau.u);
Tau.v = cat(4, data.Tau.n);
end
end
save('Tau_concatenated.mat')
  1 件のコメント
Salaijobhaka
Salaijobhaka 2016 年 10 月 4 日
It worked. Thank you for the solution.

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

その他の回答 (1 件)

Guillaume
Guillaume 2016 年 10 月 3 日
Note: there is no cell array in your mat files, just a scalar structure.
Here is how I'd solved your problem:
srcdir = 'C:\somewhere\where\mat\files\are'
mfiles = dir(fullfile(srcdir, 'tau*.mat'));
mfiles = {mfiles.name};
mfilecontent = cellfun(@(fname) load(fullfile(srcdir, fname)), mfiles, 'UniformOutput', false);
temptau = [mfilecontent{:}]; %convert cell array into structure with field Tau
temptau = temptau.Tau; %convert structure of structures into a 1x100 structure
Tau.u = vertcat(temptau.u); %concatenate u field
Tau.v = vertcat(temptau.v); %concatenate v field

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by