changing mean and median
2 views (last 30 days)
Show older comments
Anita Nabatanzi
on 17 Jul 2020
Commented: Rogers Tuyisenge
on 1 Aug 2020
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.
4 Comments
Accepted Answer
Fangjun Jiang
on 17 Jul 2020
Edited: Fangjun Jiang
on 17 Jul 2020
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
4 Comments
Bruno Luong
on 1 Aug 2020
You miss the row index in the data
Mean_answer(k,h)= mean(data(k,1:h))
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!