MATLAB Answers

Please explain how this matlab code works works and what it does

조회 수: 21(최근 30일)
Can anyone tell me how this code works?
clear
numofea=3;
subjectnum=10;
feanum=6;
featuredim=feanum*numofea;
windowsize=4;
numperfold=round(300-windowsize+1);
%datasize(subjectnum*numperfold,featuredim)=0;
alertfeasize(subjectnum*numperfold,featuredim)=0;
fatiguefeasize(subjectnum*numperfold,featuredim)=0;
subid0(subjectnum)=0;
y(subjectnum*2*numperfold)=0;
y(subjectnum*numperfold+1:end)=1;
foldidx(5*numperfold)=0;
%freqc=90;
filename={
% 'C:\Users\Adithya\Desktop\Eye tracking data\Li Rui Lin\eye_data_task_1 (5).mat',
% 'C:\Users\Adithya\Desktop\Eye tracking data\Li Rui Lin\eye_data_task_4.mat',
% 'C:\Users\Adithya\Desktop\Eye tracking data\Yuan Liqiang\eye_data_task_1 (5).mat',
% 'C:\Users\Adithya\Desktop\Eye tracking data\Yuan Liqiang\eye_data_task_4.mat',
% 'C:\Users\Adithya\Desktop\Eye tracking data\Adi\eye_data_task_1 (5).mat,
% 'C:\Users\Adithya\Desktop\Eye tracking data\Adi\eye_data_task_3.mat',
% 'C:\Users\Adithya\Desktop\Eye tracking data\Yu Lian\eye_data_task_1 (5).mat',
% 'C:\Users\Adithya\Desktop\Eye tracking data\Yu Lian\eye_data_task_4.mat',
% 'C:\Users\Adithya\Desktop\Eye tracking data\Subject 9\eye_data_task_1 (5).mat',
% 'C:\Users\Adithya\Desktop\Eye tracking data\Subject 9\eye_data_task_4.mat',
% 'C:\Users\Adithya\Desktop\Eye tracking data\Subject 11\eye_data_task_2.mat',
% 'C:\Users\Adithya\Desktop\Eye tracking data\Subject 11\eye_data_task_4.mat',
% 'C:\Users\Adithya\Desktop\Eye tracking data\Subject 13\eye_data_task_3.mat',
% 'C:\Users\Adithya\Desktop\Eye tracking data\Subject 13\eye_data_task_2.mat',
% 'C:\Users\Adithya\Desktop\Eye tracking data\Subject 15\eye_data_task_1 (5).mat',
% 'C:\Users\Adithya\Desktop\Eye tracking data\Subject 15\eye_data_task_2.mat',
% 'C:\Users\Adithya\Desktop\Eye tracking data\Subject 17\eye_data_task_1 (5).mat',
% 'C:\Users\Adithya\Desktop\Eye tracking data\Subject 17\eye_data_task_4.mat',
% 'C:\Users\Adithya\Desktop\Eye tracking data\Subject 19\eye_data_task_1 (5).mat',
% 'C:\Users\Adithya\Desktop\Eye tracking data\Subject 19\eye_data_task_2.mat'
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'C:\Users\Adithya\Desktop\Eye tracking data\Li Rui Lin\eye_data_task_1 (5).mat',
'C:\Users\Adithya\Desktop\Eye tracking data\Li Rui Lin\eye_data_task_4.mat',
'C:\Users\Adithya\Desktop\Eye tracking data\Yuan Liqiang\eye_data_task_1 (5).mat',
'C:\Users\Adithya\Desktop\Eye tracking data\Yuan Liqiang\eye_data_task_4.mat',
'C:\Users\Adithya\Desktop\Eye tracking data\Adi\eye_data_task_1 (5).mat',
'C:\Users\Adithya\Desktop\Eye tracking data\Adi\eye_data_task_4.mat',
'C:\Users\Adithya\Desktop\Eye tracking data\Yu Lian\eye_data_task_1 (5).mat',
'C:\Users\Adithya\Desktop\Eye tracking data\Yu Lian\eye_data_task_4.mat',
'C:\Users\Adithya\Desktop\Eye tracking data\Subject 9\eye_data_task_1 (5).mat',
'C:\Users\Adithya\Desktop\Eye tracking data\Subject 9\eye_data_task_4.mat',
'C:\Users\Adithya\Desktop\Eye tracking data\Subject 11\eye_data_task_1 (5).mat',
'C:\Users\Adithya\Desktop\Eye tracking data\Subject 11\eye_data_task_4.mat',
'C:\Users\Adithya\Desktop\Eye tracking data\Subject 13\eye_data_task_1 (5).mat',
'C:\Users\Adithya\Desktop\Eye tracking data\Subject 13\eye_data_task_4.mat',
'C:\Users\Adithya\Desktop\Eye tracking data\Subject 15\eye_data_task_1 (5).mat',
'C:\Users\Adithya\Desktop\Eye tracking data\Subject 15\eye_data_task_4.mat',
'C:\Users\Adithya\Desktop\Eye tracking data\Subject 17\eye_data_task_1 (5).mat'
'C:\Users\Adithya\Desktop\Eye tracking data\Subject 17\eye_data_task_4.mat'
'C:\Users\Adithya\Desktop\Eye tracking data\Subject 19\eye_data_task_1 (5).mat',
'C:\Users\Adithya\Desktop\Eye tracking data\Subject 19\eye_data_task_4.mat'
};
for tt=1:subjectnum
f1=filename{2*tt-1};
f2=filename{2*tt};
load(f1)
%%%%%%%%%%%%%%%%%%%%%
if tt>0
eyeData=eyeData.data;
end
%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%
%
% cleanedeye=0;
% cleanedeye(size(eyeData,1),size(eyeData,2))=0;
%
% validsizenum=1;
% for i=1:size(eyeData,1)
% cv=eyeData(i,17:18);
% dv=cv<0;
% if ~any(dv(:))
% cleanedeye(validsizenum,:)=eyeData(i,:);
% validsizenum=validsizenum+1;
% end
% end
%
% eyeData=cleanedeye(1:(validsizenum-1),:);
% %%%%%%%%%
timeidx=eyeData(:,1);
I=find(timeidx>(timeidx(end)-5*60));
sampledtime=timeidx(I);
sampledtime=sampledtime-sampledtime(1);
% eyedata0=eyeData(I,3:4); %11:12
% eyedata0(:,3:4)=eyeData(I,11:12);
eyedata0=eyeData(I,14:16); %11:12
for j=1:numperfold
tidx=find(sampledtime>(j-1) & sampledtime<(j-1+windowsize));
for k=1:numofea
eye1=eyedata0(tidx,k);
ap=statistical_fea(eye1);
alertfeasize((tt-1)*numperfold+j, ((k-1)*feanum+1):k*feanum)=ap(1:feanum);
end
subid0((tt-1)*numperfold+j)=tt;
end
load(f2)
%%%%%%%%%%%%%%%%%%%%%
if tt>0
eyeData=eyeData.data;
end
%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%
%
% cleanedeye=0;
% cleanedeye(size(eyeData,1),size(eyeData,2))=0;
%
% validsizenum=1;
% for i=1:size(eyeData,1)
% cv=eyeData(i,17:18);
% dv=cv<0;
% if ~any(dv(:))
% cleanedeye(validsizenum,:)=eyeData(i,:);
% validsizenum=validsizenum+1;
% end
% end
%
% eyeData=cleanedeye(1:(validsizenum-1),:);
%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%
timeidx=eyeData(:,1);
I=find(timeidx>(timeidx(end)-5*60));
sampledtime=timeidx(I);
sampledtime=sampledtime-sampledtime(1);
% eyedata0=eyeData(I,3:4);%11:12
% eyedata0(:,3:4)=eyeData(I,11:12);
eyedata0=eyeData(I,14:16); %11:12
for j=1:numperfold
tidx=find(sampledtime>(j-1) & sampledtime<(j-1+windowsize));
for k=1:numofea
eye1=eyedata0(tidx,k);
ap=statistical_fea(eye1);
fatiguefeasize((tt-1)*numperfold+j, ((k-1)*feanum+1):k*feanum)=ap(1:feanum);
end
end
end
featuredata=cat(1,alertfeasize,fatiguefeasize);
subid=cat(2,subid0,subid0);
featuredata(isnan(featuredata))=0;
save('C:\Users\Adithya\Desktop\Eye tracking data\Results','featuredata','subid','y')
function fea=statistical_fea(data)
N1=size(data,1);
m=mean(data);
sd=std(data,1);
difference=diff(data);
s=sum(abs(difference));
absm1=1/(N1-1)*s;
sdabsm1=absm1/sd;
for n=3:1:N1
out1(n-2,1)=data(n,1);
end
s_temp=0;
for n1=1:1:(N1-2)
temp=out1(n1)-data(n1);
s_temp=s_temp+abs(temp);
end
absm2=1/(N1-2)*s_temp;
sdabsm2=absm2/sd;
%higu=hitguchiFD(data', 32);
fea=[m,sd,absm1,sdabsm1,absm2,sdabsm2];
end

채택된 답변

Steven Lord
Steven Lord 10 Feb 2021
I recommend contacting the person who gave you that code or the original author of the code and asking them for help understanding it. Asking focused questions about specific lines that you find particularly difficult rather than a blanket "please tell me what this does" might allow them to target their answers and so make them more useful.

추가 답변(1개)

John D'Errico
John D'Errico 10 Feb 2021
편집: John D'Errico 10 Feb 2021
It can be almost impossible to figure out what undocumented code does, especially if we are not even told what it might be designed to do. This is especially true of code written by someone who is, let me say, a relative novice. We then might not even be certain if the code does what they wanted it to do in the first place.
Honestly, take poorly written, undocumented code like this, and deposit it firmly in the bit bucket. Don't trust it. If you need to do whatever that code is supposed to be doing, then you need to learn enough about the subject, as well as to learn enough about MATLAB, to write that code yourself. Then do exactly that. Then you will have code you can both trust and use, as well as modify when that proves to be necessary.
If you do desperately need to understand this code, then ask your questions of the author, who in theory can answer those questions more easily than can someone who has never seen the code, nor knows what it is supposed to do. If you do ask those questions, then make them SPECIFIC questions, much as we would need.
If you have no understanding of MATLAB at all, then explaining such a code in full depth would take us writing a complete course on both MATLAB as well as a course on the subject matter of the code.

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by