Variable change should not affect during loop execution?
4 次查看(过去 30 天)
显示 更早的评论
How should I not update the variable if its value is changed from dashboard during execution? For example:
If a variable value is 1 then throughout the time of execution of code it should be 1. If its value is changed from dashboard to 2 in between, then the loop should first complete its execution using the previous value and once it has completed then only the variable value should be 2 and then rest of the execution should be done. Basically, what I am trying to do is, changing variable value in between should not affect the loop, only after it has completed its execution, then it should take the new value. Can anyone guide me on how should I do it?
3 个评论
回答(1 个)
Walter Roberson
2021-11-30
Function
for variable = 1 : number_of_iterations
original_a = a;
original_b = b;
if (condition)
output = original_b;
else (condition)
output= original_a;
end
end
If a or b are changed through the dashboard any time between copying them to the original_* variables and the end of the loop iteration, then the old version wil be used until the next loop iteration.
If it is important that the user should be able to change the value with the dashboard between the time of the "for variable" loop moving to the next iteration, and the point where this code copies the variables, then a different approach would need to be taken.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Simulink Functions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!