How do you load m-files that contain filenames with integers and strings?
조회 수: 5 (최근 30일)
이전 댓글 표시
I have a foler that containes multiple files with the following naming convention:
TTsim1Variable, TTsim2Variable, TTsim3Variable, TTsim4Variable....TTsim50Variable. Each "TT" files has the same number of rows and coloumns. Currently I am using the follwing code to load the data into my workspace:
B1 = load(sprintf('TTsim1Variable.mat'));
B2 = load(sprintf('TTsim2Variable.mat'));
B3 = load(sprintf('TTsim3Variable.mat'));
This is becoming quite tedious, is there a way to use the %d notation in the file names to make this process more efficent? Perhaps something like:
B1 = load(sprintf('TTsim%dVariable.mat'));
댓글 수: 0
답변 (2개)
Stephen23
2021년 5월 18일
편집: Stephen23
2021년 5월 18일
"...is there a way to use the %d notation in the file names to make this process more efficent?"
Of course, the documentation shows the basic concept:
For your files, something like this:
P = 'absolute or relative path to where the files are saved';
N = 50;
C = cell(1,N);
for k = 1:N
F = sprintf('TTsim%dVariable.mat',k);
C{k} = load(fullfile(P,F));
end
S = [C{:}]; % optional, if all files contain the same variables.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Whos에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!