Indexing and filling matrices?

조회 수: 2 (최근 30일)
Erin Winkler
Erin Winkler 2018년 3월 30일
댓글: Stephen23 2018년 4월 4일
Hi again,
I have the following code to compute the Kaplan-Meier estimates with right-censoring:
T = size(time);
n = zeros(T(1),T(2));
d = zeros(T(1),T(2));
KMadjRank = zeros(T(1),T(2));
D = zeros(T(1),T(2));
N = zeros(T(1),T(2));
for i = 1:1000 %right for 1 column
if censoring(i) == 1 % if failed, increase number of failed by 1
d(1) = 0;
d(i+1) = d(i)+1;
end
if censoring(i) == 0 % if censored, use previous # of failed
d(i+1) = d(i);
end
n(1) = T(1); % Initialize number at risk as sample size
n(i+1) = n(i) - 1; % decrease number at risk by one
end
for i = 2:999
KMadjRank(1) = 0; % Initialize Prob of survival between 0 and first failure
KMadjRank(i) = (1-(d(i-1)/n(i-1))).*(1-(d(i)/n(i))); % KM product-limit estimator
end
So I have a 100x1000 matrix of times and of censoring and I'm trying to get KM right. Right now, this code fills out the first column correctly but I don't know how to get it to correctly index through column by column instead of as the entire thing. I want to treat this as 1000 samples of 100 so I'm trying to compute the Kaplan-Meier estimates by column so for the individual samples but I'm struggling with the coding language.
Can anyone help?
Thanks!
  댓글 수: 5
David Fletcher
David Fletcher 2018년 4월 4일
편집: David Fletcher 2018년 4월 4일
I've not been using Matlab all that long, but I have never known it not give a line number from where the error is occurring (at least not when running a script file/function). Quite often you'll get multiple line numbers from where it does a stack trace. To be honest, in that code you've posted that's the only obvious place that I can see that will give an error like that, but without a line number I don't even know if the error is coming from that function code or whatever is calling that function
Stephen23
Stephen23 2018년 4월 4일
@Erin Winkler: please give us the complete error message. This means all of the red text. Really, all of it. Do not leave any out.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by