Indexing and filling matrices?

2 visualizaciones (últimos 30 días)
Erin Winkler
Erin Winkler el 30 de Mzo. de 2018
Comentada: Stephen23 el 4 de Abr. de 2018
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 comentarios
David Fletcher
David Fletcher el 4 de Abr. de 2018
Editada: David Fletcher el 4 de Abr. de 2018
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 el 4 de Abr. de 2018
@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.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Mathematics en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by