Got Questions? Get Answers.
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:
can I use bsxfun for this?

Subject: can I use bsxfun for this?

From: Peter Schreiber

Date: 27 Dec, 2012 09:06:08

Message: 1 of 4

Hi

I have

A=[a11 a12 a13;
     a11 a12 a13;
     a11 a12 a13]

and

b=[b1 b2 b3]

and would like to compute

[ a11-b1 a12-b2 a13-b3;
     a11-b1 a12-b2 a13-b3;
     a11-b1 a12-b2 a13-b3]

The actual number of columns of A and b is typically ~100
The number of columns of A und b can vary only together (i.e. 3 columns for A and 3 columns for b)

Thanks for any help.

Peter

Subject: can I use bsxfun for this?

From: Nasser M. Abbasi

Date: 27 Dec, 2012 14:35:53

Message: 2 of 4

On 12/27/2012 3:06 AM, Peter Schreiber wrote:
> Hi
>
> I have
>
> A=[a11 a12 a13;
> a11 a12 a13;
> a11 a12 a13]
>

Are you saying A has the same rows duplicated?
Becuase that is what you wrote above.


> and
>
> b=[b1 b2 b3]
>
> and would like to compute
>
> [ a11-b1 a12-b2 a13-b3;
> a11-b1 a12-b2 a13-b3;
> a11-b1 a12-b2 a13-b3]
>
> The actual number of columns of A and b is typically ~100
> The number of columns of A und b can vary only together
>(i.e. 3 columns for A and 3 columns for b)
>
> Thanks for any help.
>
> Peter
>

Subject: can I use bsxfun for this?

From: Image Analyst

Date: 27 Dec, 2012 22:14:07

Message: 3 of 4

Peter:
Use
[rows columns] = size(A);
to get the number of rows in A, then use
B = repmat(B, [rows 1]);
to replicate B like this
b1 b2 b3
b1 b2 b3
b1 b2 b3
Then simply subtract
output = A-B;

Subject: can I use bsxfun for this?

From: Doug Schwarz

Date: 28 Dec, 2012 02:44:49

Message: 4 of 4

In article <kbh320$1fp$1@newscl01ah.mathworks.com>,
 "Peter Schreiber" <schreiber.peter15@gmail.com> wrote:

> Hi
>
> I have
>
> A=[a11 a12 a13;
> a11 a12 a13;
> a11 a12 a13]
>
> and
>
> b=[b1 b2 b3]
>
> and would like to compute
>
> [ a11-b1 a12-b2 a13-b3;
> a11-b1 a12-b2 a13-b3;
> a11-b1 a12-b2 a13-b3]
>
> The actual number of columns of A and b is typically ~100
> The number of columns of A und b can vary only together (i.e. 3 columns for A
> and 3 columns for b)
>
> Thanks for any help.
>
> Peter

Yes,

bsxfun(@minus,A,b)

--
Doug Schwarz
dmschwarz&ieee,org
Make obvious changes to get real email address.

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