matlab - What is the correct way to implement this loop that will average values with a changing counter? -
i have looked thoroughly on internet answer question, seems specific answer anywhere else. last stop.
to preface, not homework problem, is adapted online coursera course, quiz has passed. got correct answer, luck. also, more of general programming question related course, know fact within right ask on public forum.
the last thing i'm trying in matlab; if have answer in c++ or python or other high level language, wonderful, adapt solutions matlab syntax.
here is:
i have 2 vectors, t , m, each 600,000 elements/entries/integers.
t entered milliseconds 1 600,000 in ascending order, , each element in m represents 'on' or 'off' (entered 1 or 0 respectively) each corresponding millisecond entry in t. there random 1's , 0's in m correspond particular millisecond 1 600,000 in t.
i need take, starting 150th millisecond of t, , in 150 element/millisecond increments there on (inclusive), average millisecond value of groups of 150 of milliseconds entries 1 in m ('on'). example, need @ first 150 milliseconds in t, see ones have value of 1 in m, , average them. need again entries 151 300 in t, 301 450, etc. etc. these new averages should stored in new vector. problem is, number of corresponding 1's in m isn't going same every group of 150 milliseconds in t. (and yes, trying average actual value of milliseconds, values using average , order of entries in t same).
my attempt:
it turns out there 53,583 random 1's in m (out of 600,000 entries, rest 0). used 'find' operator extract entries m 1 new vector k has millisecond value corresponding t. k looks bunch of random numbers in ascending order, list of milliseconds in t 'on' (assigned 1 in m).
so k looks [2 5 11 27 39 40 79 ...... 599,698 599,727 etc.] (all of millisecond values 1 in m).
so have vector k of values need average in groups of 150, problem need go in groups of 150 based on vector t (1 600,000), means there won't same number of 1's (or values in k) in every group of 150 milliseconds in t, in turn means number need divide average of each group going change each group of 150. know need use loop average millisecond value every 150 entries, how dividing number (the number of entries each group of 150 assigned 1 or 'on') change on each iteration of loop? there way bind t , m use requisite values k whenever there 1 in m, , use simple counter average?
it's not complicated problem, hard explain. sorry that! hope explained could. appreciated, although i'm sure you'll have questions first.
thank much!
i think should work ok.
sz = length(t); n = sz / 150; k = t.*m'; t = 1; aver = zeros(n-1,1); % result vector = 1:150:sz-150 aver(t) = mean(k(i:(i+150)-1)); t = t + 1; end -rob
Comments
Post a Comment