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!