From: Edwin on
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
"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
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
"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


Use BSXFUN

bsxfun(@minus,gm,g.');


Do not use REPMAT. It costs more memory than is necessary here.
 | 
Pages: 1
Prev: Enumeration
Next: enhancement