Thread Subject: How to divide matrix by vector

Subject: How to divide matrix by vector

From: a

Date: 10 Mar, 2010 01:49:08

Message: 1 of 3

I have a matrix MxN and want each element in a column to divide by the same scalar. It means if I have N columns, I have N scalars forming a vector with N numbers.

Example:

Matrix 123
         456

divided by (2,4,5}

what I want to get is a new matrix with these elements:
1/2 2/4 3/5
4/2 5/4 6/5

Any help is appreciated.

Subject: How to divide matrix by vector

From: Bobby Cheng

Date: 10 Mar, 2010 02:11:56

Message: 2 of 3

bsxfun(@rdivide, [1 2 3; 4 5 6],[2 4 5])

"a " <davidsojka@gmail.com> wrote in message
news:hn6tqk$iq8$1@fred.mathworks.com...
>I have a matrix MxN and want each element in a column to divide by the same
>scalar. It means if I have N columns, I have N scalars forming a vector
>with N numbers.
>
> Example:
>
> Matrix 123
> 456
>
> divided by (2,4,5}
>
> what I want to get is a new matrix with these elements:
> 1/2 2/4 3/5
> 4/2 5/4 6/5
>
> Any help is appreciated.
>

Subject: How to divide matrix by vector

From: a

Date: 10 Mar, 2010 03:14:08

Message: 3 of 3

Cool, thanks Bobby!
David

"Bobby Cheng" <bcheng@mathworks.com> wrote in message <hn6v5d$dg1$1@fred.mathworks.com>...
> bsxfun(@rdivide, [1 2 3; 4 5 6],[2 4 5])
>
> "a " <davidsojka@gmail.com> wrote in message
> news:hn6tqk$iq8$1@fred.mathworks.com...
> >I have a matrix MxN and want each element in a column to divide by the same
> >scalar. It means if I have N columns, I have N scalars forming a vector
> >with N numbers.
> >
> > Example:
> >
> > Matrix 123
> > 456
> >
> > divided by (2,4,5}
> >
> > what I want to get is a new matrix with these elements:
> > 1/2 2/4 3/5
> > 4/2 5/4 6/5
> >
> > Any help is appreciated.
> >
>

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com