From: Ulrik Nash on 17 Mar 2010 11:41 This one might be a little tricky, but I hope someone is able to figure it out! Suppose I have a horizontal vector, A. For example: A = [2 3 5 5 1 4] Suppose also that I have two vertical vectors, START and END. For example: START = [1 3 4 6] END = [2 5 5 6] Now I wish to create a vertical vector, which contains the average of the values in A, from the index value contained in START to the index value contained in END. In this example: AVERAGES = [(2+3)/2 (5+5+1)/3 (5+1)/2 4/1)] I appreciate the help. Regards, Ulrik.
From: dpb on 17 Mar 2010 12:36 Ulrik Nash wrote: .... > Suppose I have a horizontal vector, A. For example: > > A = [2 3 5 5 1 4] > > Suppose also that I have two vertical vectors, START and END. For example: > > START = [1 3 4 6] > > END = [2 5 5 6] > > Now I wish to create a vertical vector, which contains the average of > the values in A, from the index value contained in START to the index > value contained in END. In this example: .... Straightahead sol'n -- use S and E for brevity avg=zeros(length(S),1); % preallocate for idx=1:length(S) avg(idx) = mean(A(S(idx):E(idx))); end --
From: Matt J on 17 Mar 2010 15:09 arrayfun(@(s,e) mean(A(s:e)),START,END)
From: dpb on 17 Mar 2010 15:28 Matt J wrote: > > arrayfun(@(s,e) mean(A(s:e)),START,END) Yeah, the "modern" way to implement my earlier "straightahead" sol'n... Unfortunately, here I see >> help arrayfun arrayfun.m not found. >> % :( Wish a retired geezer could justify the upgrade cost... I've complai^h^h^h^h^hpled before but TMW doesn't seem to have much pity... :) --
From: Matt J on 17 Mar 2010 15:39 dpb <none(a)non.net> wrote in message <hnraj9$oqk$1(a)news.eternal-september.org>... > Unfortunately, here I see > > >> help arrayfun > > arrayfun.m not found. > > >> % :( Wish a retired geezer could justify the upgrade cost... > > I've complai^h^h^h^h^hpled before but TMW doesn't seem to have much > pity... :) ==================== I wouldn't upgrade for arrayfun alone. It's been observed in various threads that it rarely outperforms a for-loop speed-wise.
|
Next
|
Last
Pages: 1 2 3 Prev: Simulink Viewer Signal Selection Parameterization Next: How to suppress plot window? |