2017-09-28 92 views
0

我正在准备一个GUI,通过在两个不同轴上的复选框选择来控制绘图的可见性。另外,用户应该从弹出菜单中选择Y向量。代码工作正常(可能更优雅),但我有自动刷新情节的问题。目前,如果我绘制并随后从弹出菜单中选择不同的Y值,则必须取消选中并重新勾选要在绘图中进行更改的复选标记。如何选择(复选标记),如何自动刷新绘图?任何帮助是非常赞赏:不断更新GUI绘图

这是我的代码:

 % --- Executes on pushbutton1. 
    function pushbutton1_Callback(hObject, eventdata, handles) 
    X=[1 2 3 4] 
    Y1=[10 20 30 40] 
    Y2=[-1 -2 -3 -4] 
    handles.X=X; 
    handles.Y1=Y1; 
    handles.Y2=Y2; 
    guidata(gcbo, handles); 
    UnitFcn(handles) 



    % --- checkbox function on/off 
    function C = OnOffStr(D) 
    OffOn = {'off', 'on'}; 
    L  = (D ~= 0) + 1; % 0/FALSE => 1, anything else => 2 
    if length(L) == 1 
    C = OffOn{L}; % Reply a string 
    else 
    C = OffOn(L); % Reply a cell string 
    end 



    function UnitFcn(handles) 
    Y1=handles.Y1; 

    for p = 1:numel(plotdata) 

     Unit = get(handles.popupmenu1,'Value'); 
     if (Unit==1) 
     Y(:,p)=Y1(:,p); 

     elseif (Unit==2)% 
     Y(:,p)=Y1(:,p)*100; 

     end   
    end 

    handles.Y=Y; 
    guidata(gcbo, handles); 
    PlotFcn(handles) 



    function PlotFcn(handles) 
    X=handles.X; 
    Y=handles.Y; 
    Z=handles.Y2; 

    %Plot in Axes 1 
    set(handles.axes1, 'NextPlot', 'add'); 
     handles.plot1 = plot(X,Y,'visible','off','LineWidth',2, ... 
           'color', [0 0 0],'linestyle', '--', 'parent', handles.axes1);  

    %Plot in Axes 2 
    set(handles.axes2, 'NextPlot', 'add');  
     handles.plot2 = plot(X,Y2,'visible','off','LineWidth',2, ... 
           'color', [0 0 0],'linestyle', '--', 'parent', handles.axes2); 

    guidata(gcbo, handles); 



    % --- Executes on button press in checkbox1. 
    function checkbox1_Callback(hObject, eventdata, handles) 
    set(handles.plot1, 'Visible', OnOffStr(get(hObject,'Value'))); 


    % --- Executes on button press in checkbox1. 
    function checkbox1_Callback(hObject, eventdata, handles) 
    set(handles.plot2, 'Visible', OnOffStr(get(hObject,'Value'))); 



    % --- Specify unit in popupmenu1. 
    function popupmenu1_Callback(hObject, eventdata, handles) 
    UnitFcn(handles) 

    function popupmenu1_CreateFcn(hObject, eventdata, handles) 
    if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 
     set(hObject,'BackgroundColor','white'); 
    end 

这是一个简化的代码和“对于p = 1:numel(plotdata)”是指一个矩阵,其中我有〜30个不同的地块。

回答

0

我能解决这个问题,如果我有这个代码在PlotFcn:

for i=1:1:numel(X(1,:)) 
Checked(i,1) = get(handles.(sprintf('checkbox%d',i)),'value'); 
if (Checked(i,1)==1) 
    set(handles.plot(i), 'Visible', 'on') 
    set(handles.plot(i), 'Visible', 'on') 
end 
end 

,但我不知道这是最好的解决办法?用这段代码运行30个图需要一些时间。