adding vectors: positive single digit values and returning digits of sum as elements of vector
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
Walter Roberson
2013-10-30
Has not been merged as both versions have Answers.
采纳的回答
Image Analyst
2013-10-30
Please give an example to show what you want. It could either be
theSum = vector1 + vector2;
like Matt J suggested, or
theSum = sum(vector1) + sum(vector2);
which will work for vectors of different lengths. Or maybe you want to interpolate them to make them equal sizes before summing - we have no idea what you really want. Don't use sum as the name of a variable like you did because sum() is the name of a built in function and you'll disable it if you use the same name for your own functions or variables.
1 个评论
Cedric
2013-10-30
My guess is that she wants something like an addition the way we do it by hand, with numbers given by digits stored in vectors.
PS: thank you for your comment yesterday. I replied but quite late!
更多回答(2 个)
Walter Roberson
2013-10-30
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!