MATLAB: Changing mean and median

changing meanchanging median

i have a column vector of 100 rows and would like to calculate its progressive median and mean for example (at the first row, only consider that row; at second row, consider first 2 rows; at third row, consider the first 3 rows and so on upto 100th row). I have used a for loop with sum/i to calculate the mean but I have failed to break through in calculating median. Kindly provide a solution or any alternatives.

Best Answer

M=100;
data=(1:M).';
MeanData=data;
MedianData=data;
for k=1:M
MeanData(k)=mean(data(1:k));
MedianData(k)=median(data(1:k));
end
Related Question