changing mean and median

2 views (last 30 days)
Anita Nabatanzi
Anita Nabatanzi on 17 Jul 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
Rachel Surridge
Rachel Surridge on 17 Jul 2020
Does your data have more than one column?
Anita Nabatanzi
Anita Nabatanzi on 17 Jul 2020
working with one column for now, will expand it out to the rest of the matrix if successful at this stage.

Sign in to comment.

Accepted Answer

Fangjun Jiang
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
Bruno Luong on 1 Aug 2020
You miss the row index in the data
Mean_answer(k,h)= mean(data(k,1:h))
Rogers Tuyisenge
Rogers Tuyisenge on 1 Aug 2020
Thanks mate, this fixes the problem!

Sign in to comment.

More Answers (0)

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!