Prev: Enumeration
Next: enhancement
From: Edwin on 12 Aug 2010 04:15 Hello everyone, if I have two column vector for example gm=[1:1:100]'; g=[1:1:21]'; Could someone please show me how can I subtract each row in gm by each row in g, so I can get a new matrix with size 100x21 without using a for loop. Regards
From: Carl on 12 Aug 2010 06:43 "Edwin " <onest30(a)gmail.com> wrote in message <i40air$grs$1(a)fred.mathworks.com>... > Hello everyone, > if I have two column vector for example > gm=[1:1:100]'; > g=[1:1:21]'; > > Could someone please show me how can I subtract each row in gm by each row in g, > so I can get a new matrix with size 100x21 without using a for loop. > > > Regards Have a look at repmat you should be able to work out what to do from there.
From: Edwin on 12 Aug 2010 06:48 Thanks just in case, this is what I did Z=repmat(g,[1 size(gm,1)])-(ones(size(g,1),1))*gm'; Regards
From: Carl on 12 Aug 2010 09:04 "Edwin " <onest30(a)gmail.com> wrote in message <i40air$grs$1(a)fred.mathworks.com>... > Hello everyone, > if I have two column vector for example > gm=[1:1:100]'; > g=[1:1:21]'; > > Could someone please show me how can I subtract each row in gm by each row in g, > so I can get a new matrix with size 100x21 without using a for loop. > > > Regards Have a look at repmat you should be able to work out what to do from there.
From: Matt J on 12 Aug 2010 10:43 Use BSXFUN bsxfun(@minus,gm,g.'); Do not use REPMAT. It costs more memory than is necessary here.
|
Pages: 1 Prev: Enumeration Next: enhancement |