http://www.mathworks.com/matlabcentral/newsreader/view_thread/242702
MATLAB Central Newsreader  averaging vectors of different dimensions
Feed for thread: averaging vectors of different dimensions
enus
©19942015 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Mon, 19 Jan 2009 23:24:38 +0000
averaging vectors of different dimensions
http://www.mathworks.com/matlabcentral/newsreader/view_thread/242702#622623
perfreem@gmail.com
hello,<br>
<br>
i am tryin to average together several columns of different matrices,<br>
each column of slightly different sizes (difference might be one or<br>
two elements).<br>
for example, my columns a, b, c might be:<br>
a = my_mat1(:, 2); # size 10<br>
b = my_mat2(:, 2); # size 12<br>
c = my_mat3(:, 2); # size 11<br>
<br>
i want to make a new vector d that contains the averages of all their<br>
values. the first 10 values can be averaged, then for the 11th i want<br>
to have the average of b and c's values, and for the 12 value i only<br>
want c's value.<br>
<br>
is there an easy way to do this? a simple: a' + b' + c' ./ 3 does not<br>
work because a b and c are all different sizes....<br>
<br>
thank you.

Tue, 20 Jan 2009 00:10:04 +0000
Re: averaging vectors of different dimensions
http://www.mathworks.com/matlabcentral/newsreader/view_thread/242702#622627
Sadik
perfreem@gmail.com wrote in message <d54e80af5e1c46019f1ab7742ffb268a@g38g2000yqn.googlegroups.com>...<br>
> hello,<br>
> <br>
> i am tryin to average together several columns of different matrices,<br>
> each column of slightly different sizes (difference might be one or<br>
> two elements).<br>
> for example, my columns a, b, c might be:<br>
> a = my_mat1(:, 2); # size 10<br>
> b = my_mat2(:, 2); # size 12<br>
> c = my_mat3(:, 2); # size 11<br>
> <br>
> i want to make a new vector d that contains the averages of all their<br>
> values. the first 10 values can be averaged, then for the 11th i want<br>
> to have the average of b and c's values, and for the 12 value i only<br>
> want c's value.<br>
> <br>
> is there an easy way to do this? a simple: a' + b' + c' ./ 3 does not<br>
> work because a b and c are all different sizes....<br>
> <br>
> thank you.<br>
<br>
How about this one [I believe in the text you have written c instead of b, because in the code, it seems that it is b whose length is 12]:<br>
<br>
([a;0;0]+b+[c;0])./[3*ones(length(a),1);2;1]

Tue, 20 Jan 2009 03:15:21 +0000
Re: averaging vectors of different dimensions
http://www.mathworks.com/matlabcentral/newsreader/view_thread/242702#622642
perfreem@gmail.com
On Jan 19, 7:10=A0pm, "Sadik " <sadik.h...@gmail.com> wrote:<br>
> perfr...@gmail.com wrote in message <d54e80af5e1c46019f1ab7742ffb2...=<br>
@g38g2000yqn.googlegroups.com>...<br>
> > hello,<br>
><br>
> > i am tryin to average together several columns of different matrices,<br>
> > each column of slightly different sizes (difference might be one or<br>
> > two elements).<br>
> > for example, my columns a, b, c might be:<br>
> > =A0 a =3D my_mat1(:, 2); # size 10<br>
> > =A0 b =3D my_mat2(:, 2); # size 12<br>
> > =A0 c =3D my_mat3(:, 2); # size 11<br>
><br>
> > i want to make a new vector d that contains the averages of all their<br>
> > values. the first 10 values can be averaged, then for the 11th i want<br>
> > to have the average of b and c's values, and for the 12 value i only<br>
> > want c's value.<br>
><br>
> > is there an easy way to do this? a simple: a' + b' + c' ./ 3 does not<br>
> > work because a b and c are all different sizes....<br>
><br>
> > =A0 =A0 thank you.<br>
><br>
> How about this one [I believe in the text you have written c instead of b=<br>
, because in the code, it seems that it is b whose length is 12]:<br>
><br>
> ([a;0;0]+b+[c;0])./[3*ones(length(a),1);2;1]<br>
<br>
hi sadik,<br>
<br>
thanks for your reply.<br>
<br>
i am talking about the general case here though, the a, b, c was just<br>
an example. i want to do this for nmany different vectors of all<br>
potentially slightly different sizes...

Tue, 20 Jan 2009 06:52:01 +0000
Re: averaging vectors of different dimensions
http://www.mathworks.com/matlabcentral/newsreader/view_thread/242702#622671
Bruno Luong
% Data<br>
a=rand(10,1);<br>
b=rand(12,1);<br>
c=rand(11,1);<br>
v={a b c};<br>
<br>
% Algo<br>
m=max(cellfun(@length,v));<br>
n=length(v);<br>
V=zeros(m,n);<br>
mask=zeros(m,n);<br>
for i=1:length(v)<br>
vi=v{i};<br>
V(1:length(vi),i)=vi;<br>
mask(1:length(vi),i)=ones(size(vi));<br>
end<br>
<br>
MeanV = sum(V.*mask,2)./sum(mask,2)<br>
<br>
% Bruno