Looping through column rows and filling another matrix by columns?
    2 次查看(过去 30 天)
  
       显示 更早的评论
    
Hi all,
I am trying to find ranks with a specific method for failure times with censoring. I am able to go through my loop and get the appropriate answers for the ranks for the first sample (100 failure times). But I have 1000 samples of 100 times to do this for and I need to fill another matrix with the ranks for the individual sample sets of 100. I can't get my code to go to the next column (sample) after finishing the first and filling out the new matrix.
Here is what I have:
                  function [BenardRanks] = CensMedianRanks(censoring,T,time)
                      % ***Find Adjusted Median Ranks for randomly generated data***
                      % sort the matrix of observed times
                      % & sort censoring matrix accordingly
                      % (to ensure censored items remain censored even when sorted)
                      A = time;
                      B = censoring;
                      [SA,I] = sort(A);
                      J = 0:size(A,2)-1;
                      x = I + J*size(A,1);
                      adjCensoring = B(x);
                      % create a matrix of integer rates (transpose(1,2,3,...,T(1)-1,T(1))
                      c = zeros(T(1),T(2));
                      C = repmat((1:size(c,1))',1,size(c,2));
                      % reverse the ranks matrix by sample
                      reverseRanks = flip(C);
                      % initialize previously adjusted ranks (PAR) to 0
                      PAR = 0;
                      % initialize matrix of indiviual sample results sampleMRAdj
                      sampleMRAdj = zeros(T(1),T(2));
                      % initialize large matrix to append individual samples to
                      MedRankAdj = zeros(T(1),T(2));
                      MedianRanksCens = [];
                      % declare empty vector (of zeros) to hold BenardRanks (size = Ranki)
                      BenardRanks = zeros(T(1),T(2));
                      % set all censored reverse ranks to 0 (censored units don't get ranks themselves but influence other ranks)
                      for k =1:T(1)
                          if censoring(k) == 0
                              reverseRanks(k) = 0;
                          end
                      end
                          for i=1:T(1)
                              if reverseRanks(i) ~= 0
                                  sampleMRAdj(i) = ((reverseRanks(i)*PAR)+(T(1)+1))/(reverseRanks(i)+1);
                              elseif reverseRanks(i) == 0
                                  sampleMRAdj(i) = sampleMRAdj(i-1);
                              end
                              PAR = sampleMRAdj(i);
                          end
                          % Benard's Approximation for Median Ranks
                          % index through Ranks with loop to calculate and store BenardRanks
                          for j = 1:T(1)
                              if sampleMRAdj(j) ~= 0
                                  BenardRanks(j) = (sampleMRAdj(j)-0.3)/(T(1)+0.4);
                              end
                          end
                          MedianRanksCens = [MedianRanksCens,BernardRanks]
                end
        I want MedianRankCens to be all the adjusted median ranks (the bernard approximations) for the individual samples.
        Help?
        Thanks!
0 个评论
回答(0 个)
另请参阅
类别
				在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
