Initially, my data had a different number of rows for each individual column. Having said that, I was able to add "0" for all the data that so that they all had a row equal to the max number of rows. Now, Im in a situation where I want to find the mean of each column but without accounting for the 0's that I added. Thus, I need to tell matlab to stop if it sees a zero but the problem is that some of the data actually has "0"'s in 1 first row for example. So far what I have is something along the lines of this by executing an for-loop combined with an if statement as follows:
d = 0.95;Z = [0 2 3; 4 5 6; 7 8 9; 0 9 0; 0 0 0; 0 0 0];i = 1;for j = length(Z-1):-1:1 if X(j,:) == 0 P(j,:) = (1/i)*sum(((1-d)*(d.^(i)))*Z); else P(j,:) = (1/(i + 1))*sum(((1-d)*(d.^(i)))*Z); endend
- So for the matrix that I have constructed, how can I tell it to count the zero with the first row but not the last 2 rows ? So far my if statement does not work at all and it just outputs a value in the first row and then the same values in the rest.
- Also, I am wondering how I can at the same time build up an accumulator that counts the number of rows it has already gone through. I am not sure if I have done it properly in my for loop here but the idea is that I want to add it to the number of samples for the calculation of my mean if it is not 0 and increase it for each non-zero value. I am not sure if the i will continue to accumulate in each loop in this case if I predefine it.The j is the fact that I want to do a reverse starting from the bottom so that the most recent date has the most weight placed to it. Any help is much appreciated in advance. I have attached a data file to work with if my explanation is not clear.
Best Answer