Update variable according to new solution in a while loop
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Rik
am 1 Mär. 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.
Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!