Quantcast
Channel: MATLAB Central Newsreader Recent Posts
Viewing all articles
Browse latest Browse all 19628

Re: vector manipulation

$
0
0
"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);

Viewing all articles
Browse latest Browse all 19628

Trending Articles