필터 지우기
필터 지우기

Load multiple files one by one into a subfolder or Extract data from strut

조회 수: 2 (최근 30일)
Hi,
How can I load multiple files from a subfolder without merging them into a strut. ?
or
I have a .mat files in a folder I have loaded them using the command below.
matpath = 'C:..\..sol_file\';
matfiles = dir(fullfile(matpath ,'*.mat'));
Please how can I extract the files separately ?
  댓글 수: 6
Stephen23
Stephen23 2023년 10월 19일
편집: Stephen23 2023년 10월 19일
You can extract the imported file data into its own structure array, which will make the data easier to access. This assumes that each scalar structure in the DATA field has exactly the same fields (which so far you have not told us).
Given your structure S, after the file importing loop do this:
Z = [S.data];
After that you can trivially use indexing to access the data, e.g. for the 2nd file:
S(2).name % filename
Z(2).helloworld % the fields which so far you have not told us what they are called
Z(2).otherfields
Z(2).etcetcetc
Do NOT try to magically create all of that data as separate variables in the workspace. There be dragons.

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

채택된 답변

Voss
Voss 2023년 10월 19일
matpath = 'C:..\..sol_file\';
matfiles = dir(fullfile(matpath ,'*.mat'));
full_file_names = fullfile(matpath,{matfiles.name});
for n = 1:numel(matfiles)
matfiles(n).data = load(full_file_names{n});
end
Now matfiles(1).data contains the data loaded from the 1st mat-file, matfiles(2).data contains the data loaded from the 2nd mat-file, and so on.
  댓글 수: 6
University
University 2023년 10월 19일
Exactly, I want variable xx_001, xx_01, etc.
Walter Roberson
Walter Roberson 2023년 10월 19일
format long g
val = 0.001
val =
0.001
fprintf('%.999g\n', val)
0.001000000000000000020816681711721685132943093776702880859375
val2 = val * (1-eps)
val2 =
0.001
fprintf('%.999g\n', val2)
0.00099999999999999980397624721462079833145253360271453857421875
MATLAB does not store numeric values in decimal. The closest representable value to 0.001 is the one shown above. Why should it create a variable name xx_001 instead of xx followed by that string of digits?
Notice that val2 displays the same as val, but has a slightly different internal value and is not the closest representable value to 1/1000 (it is the second-closest) . If that were the value in the variable, then should xx_001 still be the created variable or should it be xx followed by that long string of digits for val2 ? What is the rule here for how much values should be rounded off in creating the name of the variable?

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by