没有足够的输入参数

时间:2014-04-12 20:39:51

标签: matlab

我有一个不幸的任务,即建立一个没有经验或教育的GUI。以下代码不会在没有错误的情况下更新数字。我认为这是由于函数showFIGWINDOW(第38行没有提供WALL_LWALL_R句柄来运作refreshFIG(第86行)。

我觉得这是问题所在,因为当我将它们直接复制并粘贴到命令窗口时,这些功能起作用,但是当我按下“运行”时则不行。我怎样才能克服这个问题"没有足够的输入论据(第115行)"

任何帮助都会很出色。请原谅我的烂摊子,我编码:

function Canyon_Racer

close all
clear
clc

WIDTH_LIMIT=.005; %CONTROLS RATE OF WALL CLOSURE
DROP_COUNT=5;
CWALL_L1=0;
CWALL_L2=0;
CWALL_L3=1;
CWALL_L4=1;
CWALL_L5=0;
CWALL_L6=30;
CWALL_L7=30;
CWALL_L8=0;
CWALL_R1=14;
CWALL_R2=14;
CWALL_R3=16;
CWALL_R4=16;
CWALL_R5=0;
CWALL_R6=30;
CWALL_R7=30;
CWALL_R8=0;
CWALL_Y=30;
CLOSE=2;
CWALL_LMAX=1;
CWALL_RMIN=14;
CWALL_TMAX=30;
DELAY=.25;
POLY_NUM=1;
WALL_WIDTH=14;
gameEND=0; %causes game to intiate and continue

% TITLE = ['Welcome to CANYON RUN' 10 10 ' Out run the bandits on your tail to sruvive!' 10 10 '...but don' 10 10 'crash into the canyon walls or you' 10 10 're history' 10 10
%     '    player 1:           player 2:' 10 10 ' use (LEFT) and (RIGHT) arrow keys to stay between the walls' 10 10];

    function showFIGWINDOW

        scrsz = get(0,'ScreenSize');
        fig = figure('Position',[0, 0, 1, 1]);
        set(fig , 'Units', 'Normalized', 'OuterPosition', [0 0 .75 .75], 'color', [127 84 23]./255); %display full screen
        %         CanyonWallX_L = [CWALL_LMIN CWALL_LMAX];
        %         CanyonWallX_R = [CWALL_RMIN CWALL_RMAX];
        subplot('position', [0 0 1 1])
        axis([0 15 0 30])
        hold all
        WALL_L = patch([CWALL_L1 CWALL_L2 CWALL_L3 CWALL_L4], [CWALL_L5 CWALL_L6 CWALL_L7 CWALL_L8], [0 0 0], 'edgecolor', 'none');
        WALL_R = patch([CWALL_R1 CWALL_R2 CWALL_R3 CWALL_R4], [CWALL_R5 CWALL_R6 CWALL_R7 CWALL_R8], [0 0 0], 'edgecolor', 'none');
        set(WALL_L, 'FaceColor', [127 84 23]./255)
        set(WALL_R, 'FaceColor', [127 84 23]./255)
        set(gca, 'XTick', [],'YTick', [], 'color', [184 95 0]./255)
        set(fig,'Name','Canyon Racer v1.0','NumberTitle','off', 'toolbar', 'none', 'menubar', 'none')
        movegui(fig,'center');
        RACER_handle = patch([5 6 5.5], [3 3 5.5], [0 0 0]);

        %%% Check this for uicontrol stuff: http://www.mathworks.com/help/matlab/ref/uicontrol.html
        TBX = uicontrol( 'style', 'edit', 'String', 'Hi', 'Position', [.5, .5, 100.5, 15.5] );%%%%%%% DR. V

        %%% Check out the "KeyPressFcn/KeyReleaseFcn portion of this:
        %%% http://www.mathworks.com/help/matlab/ref/figure_props.html
        set(fig, 'KeyPressFcn', {@KeyPressed, TBX, RACER_handle} )   %%%%%%% DR. V
        set(fig, 'KeyReleaseFcn', {@KeyReleased, TBX})   %%%%%%% DR. V

    end

    function newGame

    end

    function KeyPressed( src, event, TBX, RACER_handle)   %%%%%%% DR. V
        set( TBX, 'String', sprintf('%s Pressed', event.Key ) );%%%%%%% DR. V
        if strcmp(event.Key, 'leftarrow')
            MOVE_handle = get(RACER_handle,'XData');
            set(RACER_handle, 'XData', MOVE_handle-.1 );
        elseif strcmp(event.Key, 'rightarrow')
            MOVE_handle = get(RACER_handle,'XData');
            set(RACER_handle, 'XData', MOVE_handle+.1 );
        end
    end   %%%%%%% DR. V

    function KeyReleased( src, event, TBX)   %%%%%%% DR. V
        set( TBX, 'String', sprintf('%s Released', event.Key ) );%%%%%%% DR. V
    end   %%%%%%% DR. V

    function refreshFIG( src, event, WALL_L, WALL_R)
        pause(DELAY)

         SPEED_MOVE=1;
%         if DROP_COUNT==5
%             
%             CWALL_L3=randi(CLOSE);
%             while CWALL_L3>CLOSE
%                 CWALL_L3=randi(CLOSE);
%             end
%             if POLY_NUM==0
%                 WALL_L = patch([0 0 CWALL_L3 CWALL_L4], [CWALL_Y CWALL_Y+5 CWALL_Y+5 CWALL_Y], [0 0 0], 'edgecolor', 'none');
%                 WALL_R = patch([CWALL_L4+WALL_WIDTH CWALL_L3+WALL_WIDTH 15 15], [CWALL_Y CWALL_Y+5 CWALL_Y+5 CWALL_Y], [0 0 0], 'edgecolor', 'none');
%                 set(WALL_L, 'FaceColor', [127 84 23]./255)
%                 set(WALL_R, 'FaceColor', [127 84 23]./255)
%                 CWALL_L4=CWALL_L3;
%             elseif POLY_NUM>0
%                 WALL_L = patch([0 0 CWALL_L3 CWALL_L4], [CWALL_Y CWALL_Y+5 CWALL_Y+5 CWALL_Y], [0 0 0], 'edgecolor', 'none');
%                 WALL_R = patch([CWALL_L4+WALL_WIDTH CWALL_L3+WALL_WIDTH 15 15], [CWALL_Y CWALL_Y+5 CWALL_Y+5 CWALL_Y], [0 0 0], 'edgecolor', 'none');
%                 set(WALL_L, 'FaceColor', [127 84 23]./255)
%                 set(WALL_R, 'FaceColor', [127 84 23]./255)
%                 CWALL_L4=CWALL_L3;
%             end
%             if POLY_NUM==6
%                 POLY_NUM=1;
%             end
%             
%         end
        DROP_WALL_L = get(WALL_L, 'YData');
        set(WALL_L, 'YData', DROP_WALL_L-SPEED_MOVE)
        DROP_WALL_R = get(WALL_R, 'YData');
        set(WALL_R, 'YData', DROP_WALL_R-SPEED_MOVE)
%         for NUM=(1:POLY_NUM)
%             DROP_WALL_L = get(WALL_L(NUM), 'YData');
%             set(WALL_L(NUM), 'YData', DROP_WALL_L-SPEED_MOVE)
%             DROP_WALL_R = get(WALL_R(NUM), 'YData');
%             set(WALL_R(NUM), 'YData', DROP_WALL_R-SPEED_MOVE)
%         end
        POLY_NUM=POLY_NUM+1;
        %                 DROP_COUNT=DROP_COUNT+1;
        %         CWALL_LMAX=CWALL_LMAX+WIDTH_LIMIT; %LEFT WALL CLOSING IN
        %         CWALL_RMIN=CWALL_RMIN-WIDTH_LIMIT; %RIGHT WALL CLOSING IN
        %         WALL_L = patch([0 CWALL_LMAX], [CWALL_TMAX CWALL_TMAX]); %POST TO FIG WINDOW
        %         WALL_R = patch([CWALL_RMIN, 15], [CWALL_TMAX CWALL_TMAX]); %POST TO FIG WINDOW
        %         set(WALL_L, 'FaceColor', [127 84 23]./255) %FIG WALL AREA COLOR
        %         set(WALL_R, 'FaceColor', [127 84 23]./255) %FIG WALL AREA COLOR
    end


%Game Primary Script
showFIGWINDOW
newGame
while gameEND==0
    %     moveWall;
    refreshFIG;
    %     checkWALL;
end
% close(fig);
%
%
end

1 个答案:

答案 0 :(得分:2)

  

我有一个不幸的任务,即建立一个没有经验或教育的GUI。

如果您拥有优秀的MATLAB documentation,则无需经验和教育。

发生此错误是因为graphics handles WALL_RWALL_Lnested function showFIGWINDOW中定义,但在另一个嵌套函数{{1}中使用}。要使这两个句柄在两个嵌套函数中都可见,它们应该在父函数中定义。所以,添加行

refreshFIG

在主要功能的开头(例如,在WALL_L=0; WALL_R=0; 之后)。

但这还不够,因为这些句柄被错误地重新定义为行中WALL_WIDTH=14;的参数

refreshFIG

因此,当调用此函数时,在父函数中定义的这些句柄将被同名的参数隐藏(在function refreshFIG( src, event, WALL_L, WALL_R) 的调用中未定义)。要解决此问题,请从函数参数中删除句柄名称。

此后游戏似乎运行顺利,但与some other canyon racing相比,它有点无聊;)