Loading multiple structure from a folder

조회 수: 6 (최근 30일)
University 2024년 2월 23일
댓글: Matt J 2024년 2월 24일
I am tried load multiple structures from a folder but I got a error
filepath = '..\sol_active_case11\';
mydata = dir(fullfile(filepath,'*.mat'));
full_file_names = fullfile(filepath,{mydata.name});
%% natsortfiles: Sorts text by character code and by number value
% By default matches integer substrings and performs a case-insensitive ascending sort.
% Options to select the number format, sort order, case sensitivity, etc.
mydata = natsortfiles(mydata);
for n = 1:numel(mydata)
F = fullfile(mydata(n).folder,mydata(n).name);
mydata(n).data = load(F);
A = [mydata.data];
Error using horzcat Number of fields in structure arrays being concatenated do not match.
Concatenation of structure arrays requires that these arrays have the same set of fields.
Error in Active_flow1D_case11_plot (line 23)
A = [mydata.data];

채택된 답변

Matt J
Matt J 2024년 2월 24일
편집: Matt J 2024년 2월 24일
It is because not all of the sub-structures mydata(n).data have the same fields. If you contest that, attach the mydata variable in a .mat file for us so that we can all examine it.
  댓글 수: 7
University 2024년 2월 24일
Oh, thank you so much
Matt J
Matt J 2024년 2월 24일
You're welcome, but please Accept-click the answer if the question is resolved.

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

추가 답변 (0개)


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




Community Treasure Hunt

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

Start Hunting!

Translated by