matlab uicontrol radiobutton问题

时间:2014-05-15 11:07:34

标签: matlab matlab-guide uicontrol

我有一个2d图(hhh句柄)完成了imagesc,如果按下radiobutton,我想添加一行,如果释放按钮,则删除相同的留置权。

当按下按钮时,线条显示OK,但是如果释放按钮则会出现此错误:

未定义的函数或变量'Hline'

Lokks系列程序无法记住Hline值,即使它正在使用guidata进行更新。我究竟做错了什么?感谢

这是函数

function  abc(x)
% x is a m x n matrix
hhh=imagesc(x)

% now a pushbutton to put or remove a line in the above plot

uicontrol('Style','radiobutton','String','put_remove_line',...
    'units','normalized','pos', [tf_left 0 .1/2 1/25],'parent',hhh,'HandleVisibility','on', 'fontSize',6,'Callback',{@put_remove_line ,delta_f_line, hhh ,Hline});

end % end abc function
%radiobutton callback function

function put_remove_line(hObject,event,delta_f_line,hhh,Hline)

        a=get(hObject,'Value');
        if a % if button is pressed a 
                axes(hhh)
                xlimits=get(gca,'XLim');
                Hline.xxx=line(xlimits,[delta_f_line], 'LineStyle',':','LineWidth',2);

        else
            delete(Hline.xxx,)
        end
guidata(hObject,Hline)
end

1 个答案:

答案 0 :(得分:0)

来自documentation的回调:

  

如果您定义其他输入参数,则传递给您的值   当最终用户触发时,回调必须存在于工作空间中   回调。

如上所述,当执行uicontrol()时,您的函数将仅传递Hc(x)范围内存在的Hline值。您收到错误,因为它未定义,因此Undefined function or variable 'Hline'。要解决此问题,请使用现有的guidata存储方法在put_remove_line()开头检索Hline。

假设Hline存储在guidata

function  abc(x)
% x is a m x n matrix
hhh = figure
hhh2 = imagesc(x)

% now a pushbutton to put or remove a line in the above plot

uicontrol('Style','radiobutton','String','put_remove_line',...
    'units','normalized','pos', [tf_left 0 .1/2 1/25],'parent',hhh,'HandleVisibility','on', 'fontSize',6,'Callback',{@put_remove_line ,delta_f_line, hhh});

end % end abc function
%radiobutton callback function

function put_remove_line(hObject,event,delta_f_line,hhh)

        Hline = guidata(hObject)
        a=get(hObject,'Value');
        if a % if button is pressed a 
                axes(hhh)
                xlimits=get(gca,'XLim');
                Hline.xxx=line(xlimits,[delta_f_line], 'LineStyle',':','LineWidth',2);

        else
            delete(Hline.xxx)
        end
guidata(hObject,Hline)
end

编辑:我刚刚意识到你的代码还有其他一些东西。解决Hline错误后,您将收到另一个错误:

Error using uicontrol
An object of class uicontrol, can not be a child of class image.

这是因为您将hhh定义为无法生成孩子的图像。我已对代码进行了另一次修改以解决错误,这只是打开一个数字窗口作为父对象。

相关问题