Please help with insights
Mostrar comentarios más antiguos
Problem: Assuming you have n=[16,18,23,24,39,40] values, how would you create a funtionality in Matlab to output the number of values needed to make a sum of 100, every time you call out a random value amongst them.
To eplain further: Assume it's a dart board, and the question is, how many darts do I need to throw and hit any number and after a number of throws the hit numbers add up to a 100?
I'm new to Matlab but I would solve the same with C/C++. Any insights are highly appreciated.
Respuestas (1)
Azzi Abdelmalek
el 19 de Abr. de 2013
Editada: Azzi Abdelmalek
el 19 de Abr. de 2013
n=[16,18,23,24,39,40]
find(cumsum(n)>=100,1)
%or
a=0;
k=1
while a<100 & k<numel(n)
a=a+n(k);
k=k+1;
end
out=k-1
Categorías
Más información sobre Programming en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!