Writting a loop for calculating difference from previous result of first calculation
Show older comments
I have 4 variables.
Initial_value = 50;
minimum_Value = 25;
difference_value = 5;
remaining_value = (Result)
I am trying to write a peice of code which can do following operation automatically:
step 1: Initial_value - difference_value = remaining_value
step 2: remaining_value - difference_value = new_remaining_value
step 3: new_remaining_value - difference_value = new_remaining_value_2
.
.
.
.
last step: loop stops when remaining value is equal to or less than minimum_value
To simplify I setup this example:
step 1: 50 - 5 = 45
step 2: 45 - 5 = 40
step 3: 40 - 5 = 35
step 4: 35 - 5 = 30
step 5: 30 - 5 = 25
End of loop as it reached to 25 (minimum value)
I tried writing this but it only calculates till 1 step.
for i = 100
if remaning_value(i) > minimum_value
a(i) = initial_value(i) - difference_value;
initial_value(i) = remaining_value(i);
end
end
Kindly suggest how shall i acheive this goal.
Accepted Answer
More Answers (0)
Categories
Find more on Common Operations 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!