필터 지우기
필터 지우기

Is it possible to combine two structures saved in two different .mat files?

조회 수: 7 (최근 30일)
I have two structures, both named 'data' with 17 same fields. They are basically measured data of two different dates, and I would like two combine these two. In order words, what I want is:
First .mat file: data = 1 x 85 struct array with 17 fields.
Second .mat file: data = 1 x 15 struct array with 17 fields.
---------------------------------------------------------------
Combined .mat file: data = 1 x 100 struct array with 17 fields.
If possible, I would like to avoid writing a script and rather use GUI. I also think it is possible two combine the two structures by loading both files (renaming one of them). I also would like to avoid this method.
Thanks.
  댓글 수: 2
Walter Roberson
Walter Roberson 2015년 8월 7일
Are the fields in exactly the same order between the two files?
bio lim
bio lim 2015년 8월 7일
편집: bio lim 2015년 8월 7일
Yes, they are exactly the same.

댓글을 달려면 로그인하십시오.

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2015년 8월 7일
Look at this example
q=num2cell(1:2)
p=num2cell(1:3)
a=struct('a',q,'b',q)
b=struct('a',p,'b',p)
c=[a b]
  댓글 수: 3
Walter Roberson
Walter Roberson 2015년 8월 7일
편집: Walter Roberson 2015년 8월 7일
datacell1 = load('First file.mat');
datacell2 = load('Second file.mat');
combined.data = [datacell1.data, datacell2.data];
save('Combined file.mat', '-struct', 'combined')
bio lim
bio lim 2015년 8월 7일
Thanks, Walter. Works like charm :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by