MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply TodayTo resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

Asked by Dark Warrior on 8 May 2013

Assuming you have a vector x=[16,18,23,24,39,40], create a function that when called at the command window, will display the count of random numbers(elements in vector X) needed to make a sum of 100. One should also display the combination of those random numbers.

Any help is highly appreciated.

-----------------------

The Dark Warrior

*No products are associated with this question.*

## 3 Comments

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/75025#comment_147933

http://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/75025#comment_147947

Are you sure that there exists a set of elements in your x vector that sum to 100? I tried your problem and could not find one.

By the way, my method involves using perms() and cumsum()--maybe that will help you.

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/75025#comment_147959

I am wondering if by "count" we can use one of the numbers from the list more than once (e.g., 4*16 + 2*18 = 100).