I now have the following which reads the error "Array indices must be positive integers or logical values" and I'm not sure where that's happening. But I have this now (which is more correct) but still has the same issue as before:
function [KMadjRank] = AdjustedKMrank(time,censoring)
%sampleSize = T(1)
timesort = sort(time);
T = size(time);
n = zeros(T(1),T(2));
d = zeros(T(1),T(2));
KMadjRank = zeros(T(1),1);
for i = 2:99
t = timesort(:,i);
if censoring(t) == 1 % if failed, increase number of failed by 1
d(1) = 0;
d(i+1) = d(i)+1;
end
if censoring(t) == 0 % if censored, use previous # of failed
d(i+1) = d(i);
end
n(1) = T(1); % Initialize number at risk as sample size
KMadjRank(1) = 1; % Initialize Prob of survival between 0 and first failure
KMadjRank(i+1) = (1 - d(i)/n(i))*(1 - d(i+1)/n(i+1)); % KM product-limit estimator
n(i+1) = n(i) - 1; % decrease number at risk by one
end
end