Creating for loop with an if statement
이전 댓글 표시
Hi, I have 100 data files, 50 of the files are of one set named interictal going from 1-50 and the other 50 named ictal also going from 1-50. I am trying to load the first 50 of interictal then 50 of the ictal after. I am trying to load both in one for loop and am struggling to do so. With my code so far I am able to load all 50 of the interictal but after that it loads one ictal then tries to load interictal 51 which it cannot as it doesnt exist. any help would be much appreciated.
s=100
H=zeros(1,s)
for segment=1:s
if segment==50
filename=['MATLAB/matlab 2023/data/Patient_5_ictal_segment_',num2str(segment),'.mat']
load(filename)
end
filename=['MATLAB/matlab 2023/data/Patient_5_interictal_segment_',num2str(segment),'.mat']
load(filename)
end
답변 (1개)
dpb
2023년 8월 2일
I'd go at this differently...
ROOTDATADIR='MATLAB/matlab 2023/data/'; % separate out the data from the code
PATIENTFILE='Patient_5'; % select the particular patient wanted
d=dir(fullfile(ROOTDATADIR,PATIENTFILE,'*ictal*.mat')); % get the list of both _ictal & _interictal files
for i=1:numel(d) % and walk through it...
load(fullfile(d(i).folder,d(i).Name)) % then load each in turn...
.... do whatever with each here ... can include test for whether is _inter or not, etc., etc., ...
end
카테고리
도움말 센터 및 File Exchange에서 App Building에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!