function [Count SensoredData] = sensor(StartDate,EndDate,PatientinResearch,LogicalDeath)
if ~isdatetime(StartDate)
error('MyComponent:incorrectType',...
'Error. \nInput must be a DateTime for StartDate, not a %s.',class(StartDate))
end
if ~isdatetime(EndDate)
error('MyComponent:incorrectType',...
'Error. \nInput must be a DateTime for EndDate, not a %s.',class(EndDate))
end
if ~isdatetime(PatientinResearch)
error('MyComponent:incorrectType',...
'Error. \nInput must be a DateTime for PatientinResearch, not a %s.',class(PatientinResearch))
end
if ~isa(LogicalDeath,'logical')
error('MyComponent:incorrectType',...
'Error. \nInput must be a Logical for LogicalDeath, not a %s.',class(LogicalDeath))
end
X = StartDate;
Y = EndDate;
E = PatientinResearch;
Z = LogicalDeath;
T = table();
[n,m] = size(X);
for i = 1 : 1 : n
if caldays(between(X,Y,'days')) >= caldays(between(X,E,'days'))
switch Z
case 0
p = 0;
T(i,:) = [i p];
case 1
p = 1;
T(i,:) = [i p];
end
end
if caldays(between(X,Y,'days')) < caldays(between(X,E,'days'))
switch Z
case 0
p = 1;
T(i,:) = [i p];
case 1
p = 0;
T(i,:) = [i p];
end
end
end
Count = T(:,1);
SensoredData = T(:,2);
end
0 Comments
Sign in to comment.