Subscript indices must either be real positive integers or logicals.
1 view (last 30 days)
Show older comments
Im trying to create a mario game and am coming across the error mentioned above on this line:
if (handles.Template(Row,Column) == 0);
The rest of the code is shown below:
[Rows Columns Color] = size(handles.Template)
for RowIndex = 1:1:Rows
for ColumnIndex = 1:1:Columns
if handles.Template(RowIndex, ColumnIndex, 2) <= 22 &&...
handles.Template(RowIndex, ColumnIndex, 3) <= 24
handles.Template(RowIndex,ColumnIndex,:) == 1;
else
handles.Template(RowIndex,ColumnIndex,:) == 0;
end
end
end
configurePin(a,'A0','AnalogInput')
CurrentX = 0;
for time = [1:1:10000];
A2Voltage = readVoltage(a, 'A0');
if A2Voltage >= 3
Row = floor(handles.SpriteAxis.Position(2)/29);
Column = floor((handles.SpriteAxis.Position(1)+15)/29);
set(handles.SpriteAxis,'xdir','normal')
set(M,'visible','off');
set(A,'visible','on');
set(R,'visible','off');
set(I,'visible','off');
axis off
pause(.04)
set(M,'visible','off');
set(A,'visible','off');
set(R,'visible','on');
set(I,'visible','off');
axis off
pause(.04)
set(M,'visible','off');
set(A,'visible','on');
set(R,'visible','off');
set(I,'visible','off');
axis off
pause(.04)
set(M,'visible','off');
set(A,'visible','off');
set(R,'visible','off');
set(I,'visible','on');
axis off
if (handles.Template(Row,Column) == 0);
handles.SpriteAxis.Position(1) = handles.SpriteAxis.Position(1)+15;
end
elseif A2Voltage < 2
Row = floor(handles.SpriteAxis.Position(2)/29);
Column = floor((handles.SpriteAxis.Position(1)-15)/29);
set(handles.SpriteAxis,'xdir','reverse')
set(M,'visible','off');
set(A,'visible','on');
set(R,'visible','off');
set(I,'visible','off');
axis off
pause(.04)
set(M,'visible','off');
set(A,'visible','off');
set(R,'visible','on');
set(I,'visible','off');
axis off
pause(.04)
set(M,'visible','off');
set(A,'visible','on');
set(R,'visible','off');
set(I,'visible','off');
axis off
pause(.04)
set(M,'visible','off');
set(A,'visible','off');
set(R,'visible','off');
set(I,'visible','on');
axis off
if (handles.Template(Row,Column) == 0)
handles.SpriteAxis.Position(1) = handles.SpriteAxis.Position(1)-15;
end
end
end
0 Comments
Accepted Answer
Jan
on 18 Jul 2017
What is your question?
You have to use the debugger to find the reason of the problem. The indices are defined here:
Row = floor(handles.SpriteAxis.Position(2)/29);
Column = floor((handles.SpriteAxis.Position(1)+15)/29);
Obviously at least one of them is not positive. You can test this easily by letting Matlab stop at the error:
dbstop if error
or use the corresponding menu in the editor. Then run the code again until it stops at the error. Now check the values of Row and Column.
Note: See http://www.mathworks.com/matlabcentral/answers/35676-why-not-use-square-brackets for modifying:
for time = [1:1:10000];
to the faster and nicer
for time = 1:10000
11 Comments
Walter Roberson
on 21 Jul 2017
If there are no "hot spots" on the sprites (places that should act differently -- e.g., does it matter whether it is Mario's foot that touches the rope compared to Mario's hand?) then it is easiest to use the centroid of the sprite as the reference point, as then the distance left and right would be the same. This does have a small challenge if the sprite is an odd number of pixels in width: you should be conscious of whether the reference point is the center of the pixel or the left edge or the right edge of the pixel.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!