Hello I am trying to make a function. I have for inputs datetime 3 of them one of them is logical. I am trying to calcutate a number from many rows. I have for loop, my max iteration is the height of my table. I have cases for logical data part of my function to decide the final output, I am unable to put the final answer in an order as output. I am getting an error with exceeding matrix dimensions.
function [Count SensoredData] = sensor(StartDate,EndDate,PatientinResearch,LogicalDeath)% X is start of the research.
% Y end date of the Research.
% E is number of days patient stay in the research
% Z is if death is occured or not.
if ~isdatetime(StartDate) error('MyComponent:incorrectType',... 'Error. \nInput must be a DateTime for StartDate, not a %s.',class(StartDate))endif ~isdatetime(EndDate) error('MyComponent:incorrectType',... 'Error. \nInput must be a DateTime for EndDate, not a %s.',class(EndDate))endif ~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))endX = StartDate;Y = EndDate;E = PatientinResearch;Z = LogicalDeath;T = table(); % totalTimeOfResearch = caldays(between(X,Y,'days'));
%
% sdn1 = datenum( Y );
% sdn2 = datenum( E );
% format long
%
[n,m] = size(X);for i = 1 : 1 : nif 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 endif 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 endendCount = T(:,1);SensoredData = T(:,2);end
Best Answer