From: condor on 15 Apr 2010 08:31 Hello, I have the following situation: Matrix COLUMN 1 COLUMN 2 COLUMN 3 a v1 a v2 a v3 b v4 b v5 b ... b v7 c ... c d d ... d vn Where "v" stays for a generic value. On column 3 on the same row of "the last a, last b, last c, last d...." I would like to have the sum of the values that have the same letter. EXAMPLE row(3,3)=v1+v2+v3 row(7,3)=v4+v5+v6+v7 etc.... I am able to do this with a loop, my question is if it's possbile to "vectorize" the solution...
From: us on 15 Apr 2010 08:39 "condor " <brunoricola(a)libero.it> wrote in message <hq70ue$c07$1(a)fred.mathworks.com>... > Hello, > > I have the following situation: > > Matrix > COLUMN 1 COLUMN 2 COLUMN 3 > a v1 > a v2 > a v3 > b v4 > b v5 > b ... > b v7 > c ... > c > d > d ... > d vn > > Where "v" stays for a generic value. > > On column 3 on the same row of "the last a, last b, last c, last d...." I would like to have the sum of the values that have the same letter. > > EXAMPLE > row(3,3)=v1+v2+v3 > row(7,3)=v4+v5+v6+v7 > > etc.... > > I am able to do this with a loop, my question is if it's possbile to "vectorize" the solution... a hint: - look at john d'errico's FEX submission http://www.mathworks.com/matlabcentral/fileexchange/8354 us
From: condor on 15 Apr 2010 09:35 "us " <us(a)neurol.unizh.ch> wrote in message <hq71d8$iv1$1(a)fred.mathworks.com>... > "condor " <brunoricola(a)libero.it> wrote in message <hq70ue$c07$1(a)fred.mathworks.com>... > > Hello, > > > > I have the following situation: > > > > Matrix > > COLUMN 1 COLUMN 2 COLUMN 3 > > a v1 > > a v2 > > a v3 > > b v4 > > b v5 > > b ... > > b v7 > > c ... > > c > > d > > d ... > > d vn > > > > Where "v" stays for a generic value. > > > > On column 3 on the same row of "the last a, last b, last c, last d...." I would like to have the sum of the values that have the same letter. > > > > EXAMPLE > > row(3,3)=v1+v2+v3 > > row(7,3)=v4+v5+v6+v7 > > > > etc.... > > > > I am able to do this with a loop, my question is if it's possbile to "vectorize" the solution... > > a hint: > - look at john d'errico's FEX submission > > http://www.mathworks.com/matlabcentral/fileexchange/8354 > > us First thanks for your answer. That code is probably too complicated for what I need .... it would be easy to do this with a loop, but I'm wondering if it is "vectorizable". This is what I did... Matrix is the name of the variable... Matrix(Matrix(1:end-1,1)-Matrix(2:end,1)~=0,3)= ?!? With this piece of code I am able to find the right rows on column 3 where I want the result of the sum but I don't know if it's possible to write the second part of the equation...? With a loop it would be easy but because I have just started using Matlab I need to understand what are the limit of vectorization.
|
Pages: 1 Prev: face morphing software Next: Convert ASCII-characters to double in simulink |