Update variable according to new solution in a while loop
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Rik
il 1 Mar 2020
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.
Risposte (0)
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!