Update variable according to new solution in a while loop
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi World,
The value of "i" is already given in an earlier part of the code, how do I ensure that the value of 'i' updates every time the 'total' updates.
I am really struggling with this, issue is as follows, the variable 'i' is given by the following code:
if r == 0
i = total - 1;
end
if r > 0
i = total + 9;
end
A while loop then starts which updates the total given below:
FlagP = DecisionTable(i,j);
while FlagP == 1
total = total + x(randi(length(x)))
%------------------------------------%
if r == 0
i = total + x(randi(length(x)));
else i = total + 8;
end
In this while loop the total changes, so the 'i' value needs to change in order for the read to be correct in the decision table.
Can anybody tell me how I can ensure that the value for 'i' updates everytime the total does?
Your help would be so helpful.
Steven Strange
댓글 수: 4
Rik
2020년 3월 1일
Did you do a Matlab tutorial? That should have taught you how to do it.
function i=myfun(total,r)
if r == 0
i = total - 1;
elseif r > 0
i = total + 9;
else
i= %r<0 (you could throw an error here as well)
end
Then in your code you can call this function whenever you need the value of i.
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!