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:
vector manipulation

Subject: vector manipulation

From: Elnaz

Date: 18 Feb, 2013 19:27:06

Message: 1 of 5

Dear all,

I want to subtract all the elements of a vector from an scalar one-by-one to get a scalar and I want to avoid looping.
For example say I want to do 8-[1 2] to get 8-1-2=5.
How can I do that?

Elnaz

Subject: vector manipulation

From: dpb

Date: 18 Feb, 2013 20:46:42

Message: 2 of 5

On 2/18/2013 1:27 PM, Elnaz wrote:
...

> I want to do 8-[1 2] to get 8-1-2=5. How can I do that?

doc sum

--

Subject: vector manipulation

From: Raymundo Marcos-Martinez

Date: 19 Feb, 2013 23:38:09

Message: 3 of 5

"Elnaz " <ebsadeghian@gmail.com> wrote in message <kftvaa$j37$1@newscl01ah.mathworks.com>...
> Dear all,
>
> I want to subtract all the elements of a vector from an scalar one-by-one to get a scalar and I want to avoid looping.
> For example say I want to do 8-[1 2] to get 8-1-2=5.
> How can I do that?
>
> Elnaz

I am sure there is a more elegant and general answer. In the meantime ...

a = 8;
b = [1 2];
x = a - b(1) - b(2);

Subject: vector manipulation

From: dpb

Date: 20 Feb, 2013 00:51:08

Message: 4 of 5

On 2/19/2013 5:38 PM, Raymundo Marcos-Martinez wrote:
> "Elnaz " <ebsadeghian@gmail.com> wrote in message
> <kftvaa$j37$1@newscl01ah.mathworks.com>...
...

>> I want to subtract all the elements of a vector from an scalar
>> one-by-one to get a scalar and I want to avoid looping. For example
>> say I want to do 8-[1 2] to get 8-1-2=5. How can I do that?
>>
...

> I am sure there is a more elegant and general answer. In the meantime ...
>
> a = 8;
> b = [1 2];
> x = a - b(1) - b(2); % --> a-(???)

doc sum % again... :)

--

Subject: vector manipulation

From: Raymundo Marcos-Martinez

Date: 20 Feb, 2013 01:16:17

Message: 5 of 5

Got it. I do not know why I did not see it before. Thanks dpb.

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