adding vectors: positive single digit values and returning digits of sum as elements of vector
Show older comments
I am trying to write a function that takes two vectors of positive single digit integer values as its input and return the digits of the sum as elements of a vector.
I have two vectors but am unsure how to start a function that will allow me to perform what is listed in the previous statement. If someonme could please help with me a starting po0int, it would be appreciated.
5 Comments
Matt J
on 29 Oct 2013
Why not simply do vector1+vector2?
KayLynn
on 29 Oct 2013
KayLynn
on 30 Oct 2013
Is it the following that you want to do?
x = [1,2,3] ;
y = [7,9] ;
and then, taking these as sets of digits, add the two numbers that they represent the way we do it by hand? I.e. adding 3 and 9, storing 2 and holding 1, etc.. ?
Walter Roberson
on 30 Oct 2013
Has not been merged as both versions have Answers.
Accepted Answer
More Answers (2)
Walter Roberson
on 30 Oct 2013
0 votes
The question cannot be answered until you reply to the question posed to you when you posted this previously. See http://www.mathworks.co.uk/matlabcentral/answers/91275#comment_176144
Hints:
>> x=str2double(char([7 2 4]+'0'))
x =
724
>> y=num2str(x+1)
y =
725
>> whos x y
Name Size Bytes Class Attributes
x 1x1 8 double
y 1x3 6 char
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!