Update variable according to new solution in a while loop

조회 수: 1 (최근 30일)
Steven Strange
Steven Strange 2020년 2월 29일
댓글: Steven Strange 2020년 3월 1일
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
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.
Steven Strange
Steven Strange 2020년 3월 1일
thank you Rik, i wil try this and see if it works, Steven Strange.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by