簡體   English   中英

如何在指南中更新軸-MATLAB

[英]how to update axes in guide - matlab

我在MATHLAB中使用GUI和Mfile編寫代碼。 在我的程序中,我有一塊木板。每次,計算機放置一塊大理石並旋轉該木板,然后從用戶那里得到一個大理石的位置並旋轉該木板的方向。在完成所有這些操作之后,我希望它在GUI中的axis1中顯示結果。 但在以下代碼的第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個部分。

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,然后從“ OpeningFnc”運行以下代碼。 你會看到我的問題。

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的末尾添加drawow()函數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM