I am stuck trying to figure this out. I have an array:
a = [ 1 1 1 2 1 1 1 3 2 1 1 2 1 1 1]
I want to add the values in the array so that it equal to 10. Once the added value reaches 10, I want the array to start adding the value again until it reaches 10. There is two problem that I face here,
1) How can I add the array so that the sum = 10 everytime. Notice that in the array, there is 3. If I add all the value before 3, I get 8 and I only need 2 from 3. I need to make sure that the remainder, which is 1 is added to the next array to get the sum 10.
2) How do I break the loop once it reaches 10 and ask it continue the summation to next value to get another 10?
I created a loop but it only works for the first part of the array. I have no idea how to make it continue. The code is as follow:
a = [ 1 1 1 2 1 1 1 3 2 1 1 2 1 1 1];
c = 0;
for i = 1:length(a)
while c < 10
c = c + a(i);
break
end
end
Please help. Thank you
a?ato array with specified value, as in the code, so if I runain Matlab, it will give me those specified values.10, I would identify the index of the last array that contribute to the sum. So in arraya, I havea[1] until a[8]that contribute to sum equal to10. However, as mentioned point (1) of the question, there will be remainder ina[8], which is1. I want to add the remainder to the the next value ina[9]to get another sum equal to10. I am not sure if my explaination is clear or not but I hope I can find some answers from this.[8,15]