Continuously update variable in function

조회 수: 10 (최근 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 CenterFile Exchange에서 MATLAB Coder에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by