Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Comparing individual cells of matrix with another matrix

Subject: Comparing individual cells of matrix with another matrix

From: Avni

Date: 8 Apr, 2013 22:47:08

Message: 1 of 7

I have a matrix A which is a 20 by 40 and matrix B which is 20 by 55. I am trying to divide each cell with matrix A with each cell in Matrix B to create a new matrix C. However, I am not trying to use loops because the program will take forever to run. I tried looking in to the bsxfun function however, it says i need both matrixes to be the same dimensions and I repmat does not really work.

Could someone please help provide some guidance wit this issue? Are there any other functions that I could use that I over looked?

Thank you in advance!

Subject: Comparing individual cells of matrix with another matrix

From: dpb

Date: 8 Apr, 2013 22:51:37

Message: 2 of 7

On 4/8/2013 5:47 PM, Avni wrote:
> I have a matrix A which is a 20 by 40 and matrix B which is 20 by 55. I
> am trying to divide each cell with matrix A with each cell in Matrix B
> to create a new matrix C. However, I am not trying to use loops because
> the program will take forever to run. I tried looking in to the bsxfun
> function however, it says i need both matrixes to be the same dimensions
> and I repmat does not really work.
> Could someone please help provide some guidance wit this issue? Are
> there any other functions that I could use that I over looked?

Well, what do you think should happen for the extra 15 columns of B that
aren't in A?

C=A./B(1:size(A,1),1:size(A,2));

is one solution if size(A) is always < size(B); otherwise you would have
to pick min() of both.

--

Subject: Comparing individual cells of matrix with another matrix

From: Avni

Date: 8 Apr, 2013 22:58:09

Message: 3 of 7

dpb <none@non.net> wrote in message <kjvhlr$28o$1@speranza.aioe.org>...
> On 4/8/2013 5:47 PM, Avni wrote:
> > I have a matrix A which is a 20 by 40 and matrix B which is 20 by 55. I
> > am trying to divide each cell with matrix A with each cell in Matrix B
> > to create a new matrix C. However, I am not trying to use loops because
> > the program will take forever to run. I tried looking in to the bsxfun
> > function however, it says i need both matrixes to be the same dimensions
> > and I repmat does not really work.
> > Could someone please help provide some guidance wit this issue? Are
> > there any other functions that I could use that I over looked?
>
> Well, what do you think should happen for the extra 15 columns of B that
> aren't in A?
>
> C=A./B(1:size(A,1),1:size(A,2));
>
> is one solution if size(A) is always < size(B); otherwise you would have
> to pick min() of both.
>
> --

Well, what do you think should happen for the extra 15 columns of B that aren't in A?

For instance A(1,1) should be compared to each value in Matrix B, so the extra 15 columns of B should still be accounted for?

Subject: Comparing individual cells of matrix with another matrix

From: dpb

Date: 8 Apr, 2013 23:15:49

Message: 4 of 7

On 4/8/2013 5:58 PM, Avni wrote:
> dpb <none@non.net> wrote in message <kjvhlr$28o$1@speranza.aioe.org>...
...

>> Well, what do you think should happen for the extra 15 columns of B that
>> aren't in A?

> For instance A(1,1) should be compared to each value in Matrix B, so the
> extra 15 columns of B should still be accounted for?

I don't see how that works...give a sample problem of (say) 4x5 and 4x3
and the result you expect.

--

Subject: Comparing individual cells of matrix with another matrix

From: Roger Stafford

Date: 8 Apr, 2013 23:25:09

Message: 5 of 7

"Avni " <aac46@drexel.edu> wrote in message <kjvi21$rd7$1@newscl01ah.mathworks.com>...
> dpb <none@non.net> wrote in message <kjvhlr$28o$1@speranza.aioe.org>...
> > On 4/8/2013 5:47 PM, Avni wrote:
> > > I have a matrix A which is a 20 by 40 and matrix B which is 20 by 55. I
> > > am trying to divide each cell with matrix A with each cell in Matrix B
> > > to create a new matrix C. .....
> > Well, what do you think should happen for the extra 15 columns of B that
> > aren't in A? .....
> For instance A(1,1) should be compared to each value in Matrix B, .......
- - - - - - - - -
  You haven't stated how you want the results arranged. The following places the quotients in an 800 by 1100 array of all possible quotient combinations:

 C = A(:)*(1./B(:).');

Roger Stafford

Subject: Comparing individual cells of matrix with another matrix

From: Bruno Luong

Date: 9 Apr, 2013 05:56:05

Message: 6 of 7

"Avni " <aac46@drexel.edu> wrote in message <kjvhdc$prc$1@newscl01ah.mathworks.com>...
> I have a matrix A which is a 20 by 40 and matrix B which is 20 by 55. I am trying to divide each cell with matrix A with each cell in Matrix B to create a new matrix C. However, I am not trying to use loops because the program will take forever to run. I tried looking in to the bsxfun function however, it says i need both matrixes to be the same dimensions and I repmat does not really work.
>
> Could someone please help provide some guidance wit this issue? Are there any other functions that I could use that I over looked?
>
> Thank you in advance!

C = bsxfun(@rdivide, A, reshape(B, [20 1 55]))

Bruno

Subject: Comparing individual cells of matrix with another matrix

From: Roger Stafford

Date: 9 Apr, 2013 16:57:18

Message: 7 of 7

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <kk0ahl$2mb$1@newscl01ah.mathworks.com>...
> C = bsxfun(@rdivide, A, reshape(B, [20 1 55]))
- - - - - - - - -
  The question is, when Avni asks "to divide each cell with matrix A with each cell in Matrix B to create a new matrix C", is C meant to have 44,000 elements or 880,000 elements? The phrasing here suggested the latter to me.

Roger Stafford

Tags for this Thread

No tags are associated with this thread.

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.

Contact us