From: Sam on
Hi all,

I need to write a code for adding two vectors of different length, e.g. x=[1 9 8] and y=[2 0 4 9], treating the row vectors as integers. Any help will be appreciated.
From: Jan Simon on
Dear Sam!

> I need to write a code for adding two vectors of different length, e.g. x=[1 9 8] and y=[2 0 4 9], treating the row vectors as integers. Any help will be appreciated.

But what do you want or expect as result???
What does "add" mean, if the vectors have different sizes?!

Kind regards, Jan
From: us on
"Sam " <sam.watts60(a)ntlworld.com> wrote in message <ho7e37$mnn$1(a)fred.mathworks.com>...
> Hi all,
>
> I need to write a code for adding two vectors of different length, e.g. x=[1 9 8] and y=[2 0 4 9], treating the row vectors as integers. Any help will be appreciated.

show CSSM an small example of an input and an expected output...

us
From: Walter Roberson on
Sam wrote:

> I need to write a code for adding two vectors of different length, e.g.
> x=[1 9 8] and y=[2 0 4 9], treating the row vectors as integers. Any
> help will be appreciated.

What kind of result are you expecting? If you are expecting every
combination of additions, 1+2, 9+4, 8+0 and so on, then see bsxfun(). If
you are expecting element-wise addition, then is the implication that
the shorter vector is to be extended with zeros before doing the additions?
From: Sam on
"Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message <ho7egc$sh0$1(a)fred.mathworks.com>...
> Dear Sam!
>
> > I need to write a code for adding two vectors of different length, e.g. x=[1 9 8] and y=[2 0 4 9], treating the row vectors as integers. Any help will be appreciated.
>
> But what do you want or expect as result???
> What does "add" mean, if the vectors have different sizes?!
>
> Kind regards, Jan

Thanks for answering Jan.

I need to add zeros at the front of the smaller number so that I can add the two up. For example x would become [0 1 9 8]. Also when they add up I need the number to extend as they must all be single digits. [9] + [8] must become [1 7] not [17].

Sam
 |  Next  |  Last
Pages: 1 2 3 4
Prev: rounding particle value using PSO
Next: Contourf