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