How to Navigate on the Matrix as Visual
1 次查看(过去 30 天)
显示 更早的评论
Hello everyone,
I am trying to navigate over matrix and show this action as visual step-by-step. Actually, I created scheme as an image that I want to work on it but I want to use another format except image because, working over an image is so hard. For instance, I labored while I was trying to show colored box on matrix due to that I have to care the pixel detail. I have attached my scheme and code below. While running the code, you should give 2 inputs which is between 0 to outs (10 for default).
Please suggest me another way to show colored boxe moves over matrix.
%Programmed by Muhammet Kurt
% renkler=uint8(renkler);
outs=10;
colors=rand(outs,3)*255;
res=50;
borderThickness=5;
whSize=(res+borderThickness)*outs;
chart=uint8(ones(whSize,whSize,3)*255);
for i=1:outs+1
fIndex=(res+borderThickness)*(i-1)+1;
LIndex=fIndex+borderThickness-1;
chart(fIndex:LIndex,1:end,1:end)=0;
if(i==outs)
useIndex=LIndex;
end
end
for j=1:outs+1
fIndex=(res+borderThickness)*(j-1)+1;
LIndex=fIndex+borderThickness-1;
chart(1:end,fIndex:LIndex,1:end)=0;
if(j<=outs)
chart(useIndex:useIndex+res,LIndex:LIndex+res,1)=colors(j,1);
chart(useIndex:useIndex+res,LIndex:LIndex+res,2)=colors(j,2);
chart(useIndex:useIndex+res,LIndex:LIndex+res,3)=colors(j,3);
end
end
figure,imshow(uint8(chart));
inPort=input('Choose the input gate to start from matrix first row: ');
inLabel=input('Enter the label of product (to arrive end of the matrix row): ');
for r=1:outs-1
rowLastIndex=(borderThickness+res)*r;
rowFirstIndex=rowLastIndex-res+1;
colLastIndex=(borderThickness+res)*inPort;
colFirstIndex=colLastIndex-res+1;
chart(rowFirstIndex:rowLastIndex,colFirstIndex:colLastIndex,1)=colors(inLabel,1);
chart(rowFirstIndex:rowLastIndex,colFirstIndex:colLastIndex,2)=colors(inLabel,2);
chart(rowFirstIndex:rowLastIndex,colFirstIndex:colLastIndex,3)=colors(inLabel,3);
imshow(uint8(chart));
pause(1)
end
if(inLabel>inPort)
for j=inPort:inLabel
rowLastIndex=(borderThickness+res)*(outs-1);
rowFirstIndex=rowLastIndex-res+1;
colLastIndex=(borderThickness+res)*j;
colFirstIndex=colLastIndex-res+1;
chart(rowFirstIndex:rowLastIndex,colFirstIndex:colLastIndex,1)=colors(inLabel,1);
chart(rowFirstIndex:rowLastIndex,colFirstIndex:colLastIndex,2)=colors(inLabel,2);
chart(rowFirstIndex:rowLastIndex,colFirstIndex:colLastIndex,3)=colors(inLabel,3);
imshow(uint8(chart));
pause(1)
end
else
for j=inPort:-1:inLabel
rowLastIndex=(borderThickness+res)*(outs-1);
rowFirstIndex=rowLastIndex-res+1;
colLastIndex=(borderThickness+res)*j;
colFirstIndex=colLastIndex-res+1;
chart(rowFirstIndex:rowLastIndex,colFirstIndex:colLastIndex,1)=colors(inLabel,1);
chart(rowFirstIndex:rowLastIndex,colFirstIndex:colLastIndex,2)=colors(inLabel,2);
chart(rowFirstIndex:rowLastIndex,colFirstIndex:colLastIndex,3)=colors(inLabel,3);
imshow(uint8(chart));
pause(1)
end
end
5 个评论
Walter Roberson
2019-4-19
Sx = 16; Sy = 16;
vimg = cat(3, zeros(Sy, Sx), ones(Sy, Sx), zeros(Sy, Sx)); %a green object
vhand = image(vimg);
for ....
new_x = ...;
new_y = ...;
set(vhand, 'XData', [new_x, new_x+Sx-1], 'YData', [new_y, new_y+Sy-1]);
drawnow();
end
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Develop uifigure-Based Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!