2014-05-15 45 views
0

我有一個2D圖(HHH手柄)與圖像c完成,如果按下單選按鈕,我想添加一行,並刪除按鈕釋放時相同的留置權。matlab uicontrol單選按鈕問題

當按鈕被按下的行顯示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 

回答

0

documentation回調:

If you define additional input arguments, then the values you pass to the callback must exist in the workspace when the end user triggers the callback.

書面的,因爲它在美國廣播公司的範圍存在於您的功能將僅通過HLINE的值( x)執行uicontrol()時。你收到一個錯誤,因爲它沒有被定義,因此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爲圖像,不能有孩子。我對代碼進行了另一次修改以解決錯誤,這只是打開一個數字窗口作爲父對象。

+0

許多很多謝謝,我會看到這一點,目前我們已經使用全球xxx,看起來不是最好的解決方案... –