用户界面 - 如何在指南中更新轴 - MATLAB



我在MATHLAB中使用GUI和Mfile编写代码。 在我的程序中,我有一个板,每次,计算机放一个弹珠并旋转板子,然后得到一个弹珠位置并从用户和 完成这些事情后,我希望它在 GUI 中的 axes1 中显示结果。 但它在以下代码的第 9 行中不起作用:

% some codes...
1.   while(currentDepth < 7)
2.   if(mod(currentDepth,2) ~= (plrC-1))
3.       plat(currentDepth);
4.       drawTable(); % show the result in axes1 --> it works
5.   else
6.       getMarble();
7.       drawTable(); % show the result in axes1 --> it works
8.       rotate();
9.       drawTable(); % show the result in axes1 --> it dosen't work
10.  end
11.  end
% some codes...

.

function drawTable()
global board;
% some codes...
imshow(board,[0 4]);
end

你有什么想法吗?

它是旋转功能。电路板分为4个部分,只有1个部分旋转。

function rotate()
global board;
block = 0;
vector = 'non';
while(block<1 || block>4)
    block = str2double(cell2mat(inputdlg('chose a block: 1/2/3/4','board rotation')));
end
switch block
    case 1
        k=1; z=1;
    case 2
        k=1; z=4;
    case 3
        k=4; z=1;
    case 4
        k=4; z=4;
end
while(~strcmp(vector,'left') && ~strcmp(vector,'right'))
    vector = questdlg('rotate left or right','Rotation','left','right','right');
end
if(strcmp(vector,'left'))
    board(k:k+2,z:z+2)=rot90(board(k:k+2,z:z+2));
else
    board(k:k+2,z:z+2)=rot90(board(k:k+2,z:z+2),3);
end
end

好的,现在我们有一个简化的代码。 用轴制作一个新的 GUI,然后从"OpenFnc"运行下面的代码。 你会看到我的问题。

function test()
currentDepth = 1;
plrC = 1;
plrO = 2;
board = zeros(6);
while(currentDepth < 40)
    if(mod(currentDepth,2) == 1)
        plat();
        drawTable(); % show the result in axes1 --> it works
    else
        getMarble();
        drawTable(); % show the result in axes1 --> it works
        rotate();
        drawTable(); % show the result in axes1 --> it dosen't work
    end
    currentDepth = currentDepth +1;
end
function plat()
    for a=1:5000
       for b=1:5000
           for c=1:50
           m = a + b;
           end
       end
    end
    row = 1;
    column = 1;
    while(board(row,column) ~= 0)
        row = randi(6);
        column = randi(6); 
    end
    board(row,column) = plrC;
    row = randi([1 4]);
    column = randi([1 4]);
    board(row:row+2,column:column+2)=rot90(board(row:row+2,column:column+2));
end
function drawTable()
    board(board==0) = board(board==0)+4;
    B = zeros(305);
    B(:,152:154) = 3;
    B(152:154,:) = 3;
    for i=1:6
        for j=1:6
            x = (i*5)+1+(i-1)*45;
            y = (j*5)+1+(j-1)*45;
            B(x:x+44,y:y+44) = board(i,j);
        end
    end
    imshow(B,[0 4]);
    board(board==4) = board(board==4)*0;
end
function getMarble()
    board(board==0) = board(board==0)+4;
    b = zeros(305);
    b(:,152:154) = 3;
    b(152:154,:) = 3;
    for i=1:6
        for j=1:6
            x = (i*5)+1+(i-1)*45;
            y = (j*5)+1+(j-1)*45;
            b(x:x+44,y:y+44) = board(i,j);
        end
    end
    imshow(b,[0 4]);
    i = 0;
    while(i~=4)
        [x,y] = ginput(1);
        if(x<0 || x>305 || y<0 || y>305)
            i = 0;
        else
            i = b(ceil(y),ceil(x));
        end
    end
    y = ceil(y/50);
    x = ceil(x/50);
    board(y,x) = plrO;
end
function rotate()
    block = 0;
    vector = 'non';
    while(block<1 || block>4)
        block = str2double(cell2mat(inputdlg('chose a block: 1/2/3/4','board rotation')));
    end
    switch block
        case 1
            k=1; z=1;
        case 2
            k=1; z=4;
        case 3
            k=4; z=1;
        case 4
            k=4; z=4;
    end
    while(~strcmp(vector,'left') && ~strcmp(vector,'right'))
        vector = questdlg('rotate left or right','Rotation','left','right','right');
    end
    if(strcmp(vector,'left'))
        board(k:k+2,z:z+2)=rot90(board(k:k+2,z:z+2));
    else
        board(k:k+2,z:z+2)=rot90(board(k:k+2,z:z+2),3);
    end
end

结束

正如

ThP所说,我必须在drawTable的末尾添加drawnow()函数。

相关内容

  • 没有找到相关文章

最新更新