'the variable appears to change size on every loop iteration' So my variable W, this happens

조회 수: 2 (최근 30일)
So my variable W, this happens...The code "The variable 'W' appears to change size on every loop iteration...'
I don't know how to fix it. Basically in this code, there is an matrix of 20 by 20 zeros. And a random zero is added with 1 on each loop. 1 can be added to make it 2 or 3.
When at least half of the zeros are not zeros anymore, it puts out the message. Same for all. Need help with 'W', thanks.
real = false;
game = 0;
hit = 0;
while real == false
game = game + 1;
ro = randi (20);
co = randi (20);
W(ro,co) = W(ro,co) + 1;
hit = 0;
for rscan = 1:20
for cscan = 1:20
if W(ro,co)>= 1
hit = hit + 1;
end
end
end
if hit == 200
fprintf('%i days have passed for half of the window to have impact', game)
end
if hit == 400
fprintf('%i days have passed for all of the window to have impact', game)
end
end
  댓글 수: 2
Geoff Hayes
Geoff Hayes 2020년 11월 16일
Hassan - according to the code, I think that W should never be more than a 20x20 array. Why do you think it is changing size?
Dominic Garcia
Dominic Garcia 2020년 11월 16일
Apparently, Matlab keeps giving the message, 'The variable 'W' appears to change size on every loop iteration..'...

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2020년 11월 16일
Before the loop do
W = zeros(20,20);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Number games에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by