Value not adding to variable in array
5 次查看(过去 30 天)
显示 更早的评论
When I run the code below and test it in my app. One of the variables in count should be 1, however, when, I display it it this is not the case. If i display the count array, for example, for f = 4. The fourth cell shows as one but if i display Count4 straight after is displays as zero. Any help would be much appreciated. Before the arrays i just had the code run for each individual set of variables (e.g. Fill1, Count 1, RAHWin, YAHWin) and the code would work as needed but turning them into arrays broke it. There seems to be a problem setting the values for count into the coutnt variable. I can attatch more code if nessecary but any help would be much appreciated.
app.Fill = {app.Fill1,app.Fill2,app.Fill3,app.Fill4,app.Fill5,app.Fill6,app.Fill7};
app.Count = {app.Count1,app.Count2,app.Count3,app.Count4,app.Count5,app.Count6,app.Count7};
app.RHWin = {app.RAHWin,app.RBHWin,app.RCHWin,app.RDHWin,app.REHWin,app.RFHWin,app.RGHWin};
app.YHWin = {app.YAHWin,app.YBHWin,app.YCHWin,app.YDHWin,app.YEHWin,app.YFHWin,app.YGHWin};
for f = 1:numel(app.Fill)
if app.Fill{f} == 1
disp(app.Count4)
app.Count{f} = app.Count{f} + 1;
app.Fill{f} = 0;
disp(app.Count{f})
if app.Past == app.Red
app.RHWin{f} = app.RHWin{f} + 1;
app.YHWin{f} = 0;
elseif app.Past == app.Yellow
app.YHWin{f} = app.YHWin{f} + 1;
app.RHWin{f} = 0;
end
end
end
0 个评论
采纳的回答
Walter Roberson
2022-4-3
You have a property named app.Count4 and that is completely different than your property app.Count . There is no connection between them, and you never change app.Count4 .
In particular, app.Count4 is not the same as app.Count(4), just like the 4th child of King James was not King James IV
2 个评论
Walter Roberson
2022-4-10
Suppose you were working with books, and indexing gave you pages. Would you expect that
ScienceFictionHallOfFame(4)
would give you the same result as
ScienceFictionHallOfFame4
??
ScienceFictionHallOfFame4 is a complete name, denoting a complete book, not page 4 of the first book.
ScienceFictionHallOfFame4 is not even the 4th book in the ScienceFictionHallOfFame series -- the series went ScienceFictionHallOfFame, ScienceFictionHallOfFame2a, ScienceFictionHallOfFame2b, ScienceFictionHallOfFame3, ScienceFictionHallOfFame4 .
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!