"someone" <someone@somewhere.net> wrote in message <icehsj$mvk$1@fred.mathworks.com>...
> "antonio ferreira" <edgar.acferreira@gmail.com> wrote in message <icegqr$d6v$1@fred.mathworks.com>...
> > Hi all.
> >
> > I have a simple matrix A=[2 3;4 6; 7 8] and I want to divide only the second column by 2, i.e., the result must be b=[2 1.5; 4 3;7 4].If I want to divide the second column by 2 I must do A(:,2)/2 but how can I "index" the first column?Thanks a lot for the suggestions.
> >
> > Regards
>
> % No need to 'index" the first column, try:
>
> A=[2 3;4 6; 7 8];
> b = A;
> b(:,2) = A(:,2)/2
>
> b =
>
> 2.0000 1.5000
> 4.0000 3.0000
> 7.0000 4.0000
>
> >>
For multiple columns/divisions etc. you could also use BSXFUN for this:
bsxfun(@rdivide,A,[1 2])
The advantage of this is if you wanted to divide the first and second column by something you wouldn't have to extract them each individually. E.g. divide the first column by 3 and the second by 2
bsxfun(@rdivide,A,[3 2])
