Workaround for matrix dimension error
显示 更早的评论
Hello guys,
I already asked a few questions about my LED-Matrix project and it is getting closer to its final state.
So when implementing my mousemode I wanted to switch between several figures which I "draw" in an array around the Mouseposition.
unction Transmit = MouseFigure(MousePos,Transmit,handles)
global click
%click = 3;
brtn = get(handles.slider1, 'Value');
switch click
case 1 %%Kreuz%%
Transmit(MousePos(1),MousePos(2)) = 255*brtn;
Transmit(MousePos(1)+1,MousePos(2)) = 255*brtn;
if MousePos(1) > 1
Transmit(MousePos(1)-1,MousePos(2)) = 255*brtn;
end
if MousePos(2) > 1
Transmit(MousePos(1),MousePos(2)-1) = 255*brtn;
end
Transmit(MousePos(1),MousePos(2)+1) = 255*brtn;
case 2 %%Rechteck 3x3 Pixel%%
for i = 1:3
if MousePos(1) < 2
i = 2;
end
Transmit(MousePos(1)-2+i,MousePos(2)+1) = 255*brtn;
Transmit(MousePos(1)-2+i,MousePos(2)) = 255*brtn;
Transmit(MousePos(1)-2+i,MousePos(2)+1) = 255*brtn;
Transmit(MousePos(1)-2+i,MousePos(2)) = 255*brtn;
if MousePos(2) > 2
Transmit(MousePos(1)-2+i,MousePos(2)-1) = 255*brtn;
end
end
case 3 %%Kreis 3,5,5,5,3%%
for i = 1:5
if MousePos(1) > 3
Transmit(MousePos(1)-3+i,MousePos(2)+1) = 255*brtn;
Transmit(MousePos(1)-3+i,MousePos(2)) = 255*brtn;
end
if MousePos(2) > 1
Transmit(MousePos(1)-3+i,MousePos(2)-1) = 255*brtn;
end
if MousePos(1) > 4
Transmit(MousePos(1)-4+i,MousePos(2)+2) = 255*brtn;
if MousePos(2) > 2
Transmit(MousePos(1)-4+i,MousePos(2)-2) = 255*brtn;
end
end
end
end
Transmit = Transmit([1:32],[1:32]);
Transmit = rot90(Transmit,1);
Transmit = reshape(Transmit,[1,1024]);
But when doing this in my method as you can see there are always those if-cases for the outer line of the drawn figure to avoid matrix dimension errors. Now my question is, is there a smarter workaround for this error or even for "drawing" those figures in my array?
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!