Loading Files using a Loop with a predictable name pattern

조회 수: 5 (최근 30일)
Zah
Zah 2022년 12월 28일
편집: Stephen23 2022년 12월 29일
Hie,
I want to load files using automated loop function into my workspace with predictable name pattern. Currently I am doing manually. Here is the photo attached for reference.
  댓글 수: 1
Stephen23
Stephen23 2022년 12월 28일
"Currently I am doing manually."
Numbering variables like that is a sign that you are doing something wrong.
Instead of forcing pseudo-indices into variable names, you should use actual indices.

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

채택된 답변

Stephen23
Stephen23 2022년 12월 28일
P = 'absolute or relative path to where the files are saved';
N = 10;
C = cell(1,N);
for k = 1:N
F = sprintf('IGP_Small_fr%d.mat',k);
C{k} = Feko_load_2DMatrix(fullfile(P,F));
end
A = cat(3,C{:}) % optional
  댓글 수: 14
Zah
Zah 2022년 12월 28일
@Voss My only concern is to load files using a loop with different names and different matrices. However its coming everything in matrice A which I dont want
Voss
Voss 2022년 12월 28일
If you don't want to use the 3D array A, then use the cell array C.
The point is that, with either of those, you will use indexing to access your matrices, rather than creating multiple variables, each containing one matrix.

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

추가 답변 (0개)

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by