Value not adding to variable in array
5 views (last 30 days)
Show older comments
Dilan Morzaria
on 3 Apr 2022
Commented: Walter Roberson
on 10 Apr 2022
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 Comments
Accepted Answer
Walter Roberson
on 3 Apr 2022
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 Comments
Walter Roberson
on 10 Apr 2022
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 .
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!