Continuously update variable in function

16 ビュー (過去 30 日間)
Steven Strange
Steven Strange 2020 年 3 月 20 日
コメント済み: Steven Strange 2020 年 3 月 20 日
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

採用された回答

darova
darova 2020 年 3 月 20 日
  6 件のコメント
darova
darova 2020 年 3 月 20 日
I made a simple scheme for you. Please see it and try to understand
Steven Strange
Steven Strange 2020 年 3 月 20 日
hi, that works! thank you so much Ameer and Darova

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB Coder についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by