22 views (last 30 days)

Renato Agurto
on 22 Dec 2015

Edited: Renato Agurto
on 22 Dec 2015

I think this should do it:

for i = 1:N

A = load(file_i);

A = struct2cell(A);

f{i} = cat(1,A{:})

end

combined_f = cat(1,f{:});

Renato Agurto
on 22 Dec 2015

My answer was arlready for multiple files. file_i should actually be file_array{i}. where

file_array = {'file1.mat',..

'file2.mat',...

'file3.mat'};

then you can use the above code:

for i = 1:N

A = load(file_array{i}); %load file i

A = struct2cell(A); %get cell array with ALL matrices in file

f{i} = cat(1,A{:}) %merge matrices of file

end

combined_f = cat(1,f{:}); %merge matrices of all files

where N is the number of files. In this case 3

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## Direct link to this comment

https://es.mathworks.com/matlabcentral/answers/261251-how-to-merge-two-mat-files-which-have-different-structure-cells-into-a-mat-file-with-a-matrix#comment_331066

⋮## Direct link to this comment

https://es.mathworks.com/matlabcentral/answers/261251-how-to-merge-two-mat-files-which-have-different-structure-cells-into-a-mat-file-with-a-matrix#comment_331066

## Direct link to this comment

https://es.mathworks.com/matlabcentral/answers/261251-how-to-merge-two-mat-files-which-have-different-structure-cells-into-a-mat-file-with-a-matrix#comment_331110

⋮## Direct link to this comment

https://es.mathworks.com/matlabcentral/answers/261251-how-to-merge-two-mat-files-which-have-different-structure-cells-into-a-mat-file-with-a-matrix#comment_331110

Sign in to comment.