Loading multiple matlab files in to a structure

조회 수: 3 (최근 30일)
WellsJ
WellsJ 2017년 11월 2일
댓글: Stephen23 2017년 11월 2일
I'm trying to load multiple matlab files in to a structure using
for m = 1:numel(data)
S(m,1) = load(data{m});
end
Where data is the file path. However i have been encountering the following message.
"Subscripted assignment between dissimilar structures."
Any help appreciated
  댓글 수: 1
Rik
Rik 2017년 11월 2일
All your .mat files must contain the same variables, otherwise an error like this is expected. You might try first loading it to a cell to get an idea of what is going wrong (or use breakpoints).

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

채택된 답변

Jos (10584)
Jos (10584) 2017년 11월 2일
This means that the variables are different across files. In a structure array, all the fields should be the same, hence the error. However, the sub-fields can be different!
So, you can use this approach:
for m = 1:numel(data)
S(m,1).content = load(data{m});
end
  댓글 수: 2
WellsJ
WellsJ 2017년 11월 2일
Perfect! Thanks!
Stephen23
Stephen23 2017년 11월 2일
Using a cell array would be an alternative.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Workspace Variables and MAT Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by