Clear Filters
Clear Filters

Can you help me understand this code?

1 view (last 30 days)
nc
nc on 4 Nov 2016
Edited: nc on 4 Nov 2016
....
  1 Comment
Adam
Adam on 4 Nov 2016
Which parts of it are you struggling with in particular? There is nothing out of the ordinary in there that isn't in the help.

Sign in to comment.

Answers (1)

John D'Errico
John D'Errico on 4 Nov 2016
Edited: John D'Errico on 4 Nov 2016
It looks like a poorly written (and wholly uncommented, which makes it very poor IMHO) code to compute a cumulative mean, then keeping track of the last time that mean falls below the value avg-0.01. This is the problem with poorly written code. Hard to read. Hard to follow. Often buggy as hell.
In two lines, three if you count the assignment of the vector k:
cumavg = cumsum(k)./(1:numel(k));
mark = find(cumavg <= (avg - 0.01),1,'last');

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!