Continuously update variable in function
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Steven Strange
le 20 Mar 2020
Commenté : Steven Strange
le 20 Mar 2020
Hi Guys, CODE BELOW
I have a function where I have the variable coun, coun is calculated
I then have a function which runs that function multiple times for a given number.
What I would like to do is run the function twice, so lets say i run it first time and then get coun = -1 i want to then use that value of coun and not start again at zero. Could someone please help me with this, thanks Steven.
CODE BELOW for calculation of count.
function [x,money] = winnings4(x)
i0 = (randi(length(x)));
j0 = (randi(length(x)));
k0 = (randi(length(x)));
while j0==i0
j0 = (randi(length(x)));
end
while k0==j0
while k0==i0
k0 = (randi(length(x)));
end
if k0==j0
k0 = (randi(length(x)));
end
end
PlayersHand = [x(i0),x(j0)]
DealersHand = [x(k0)]
a = x(i0)
b = x(j0)
c = x(k0)
coun = 0;
if a < 7 && a >= 2
coun = coun + 1
end
if a < 10 && a > 6
coun = coun + 0
end
if a == 10
coun = coun - 1
end
if a == 1
coun = coun - 1
end
if b < 7 && b > 2
coun = coun + 1
end
if b < 10 && b > 6
coun = coun + 0
end
if b == 10
coun = coun - 1
end
if b == 1
coun = coun - 1
end
if c < 7 && c > 2
coun = coun + 1
end
if c < 10 && c > 6
coun = coun + 0
end
if c == 10
coun = coun - 1
end
if c == 1
coun = coun - 1
end
x(i0) = 0;
x(j0) = 0;
x(k0) = 0;
x = x(x~=0)
%%----------------------------------------CODE FOR FUNCTION TO RUN ABOVE MULTIPLE TIMES BELOW:----------------------%%
function run4 = m()
v = [1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7,8,8,8,8,9,9,9,9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10];
deck = [v,v,v,v,v,v]; % 6 decks
y = zeros(1,100);
for k = 1:2
[deck,y(k)] = winnings4(deck);
if length(deck) < 78
run4 = sum(y);
p = length(deck);
q = k;
return
end
end
run4 = sum(y);
end
0 commentaires
Réponse acceptée
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur MATLAB Coder dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
