2014-10-14 1 views
0

현재 Matlab GUI에서 팝업 메뉴를 통해 화면에 표시된 플롯을 변경할 수있는 기능을 구축 중입니다 ....이 isn ' t 문제 FYI!) 마우스로 플롯을 가로 지르는 세로선을 이동합니다 (x- 데이터는이 줄의 위치에서 반환됩니다). GUI를 처음 생성 할 때이 마우스 대화 형 라인을 만드는 데 아무런 문제가 없지만 사용자가 팝업 메뉴에서 다른 데이터 세트를 선택하면 사용자 대화 형 라인을 "다시 생성"할 수 없습니다.(Re-) Matlab GUI에서 드래그 가능한 라인 생성하기

handles.yline1 = line([x_start x_start],[y_min,y_max],'ButtonDownFcn',@(hObject,eventdata)postprocessingtry1('startdrag1_Fcn',hObject,eventdata,guidata(hObject))); 

:

나는 GUI의 개방 기능에 다음 코드를 사용하여 드래그 라인을 구축

function startdrag1_Fcn(hObject, eventdata, handles) 

set(handles.figure2,'WindowButtonMotionFcn',@(hObject,eventdata)postprocessingtry1('dragging1_Fcn',hObject,eventdata,guidata(hObject))); 

... 그리고 "dragging1_Fcn"는를 반환하는 기능입니다 x 위치. handle.handle/설정 잘못되었거나 삭제 된 개체를 사용하여

오류 : 나는 PopupMenu로 콜백 함수 내에서 동일한 "handles.yline1 = ..."를 선언을 사용하려고하면

오류

가 발생합니다. postprocessingtry1에

오류> dragging1_Fcn (라인 341)

세트 (handles.yline1 'XDATA'pt.CurrentPoint (1,1) * [1]);

(팝업 메뉴를 통해) 새 데이터 세트를 선택하고 플로팅 한 후 사용자 대화 형 라인을 재생성하는 방법에 대한 조언은 매우 감사 할 것입니다. 지금 생각해 보면, 아마도 팝업 메뉴 콜백 함수 내에서 hObject 및 eventdata를 참조하는 것이 문제와 관련이있을 수 있습니다.하지만 확실하지 않습니다!

여기

+0

귀하의 콜백 함수 선언은 저에게 모호합니다. 왜 단순히'handles.yline1 = line (..., 'ButtonDownFcn', @ startdrag1_Fcn); 콜백 함수를 정의 할 때마다'postprocessingtry1'를 호출해야 할 이유가 있습니까? – Hoki

+0

@Hoki와 동의하십시오. 그렇지 않으면 생각으로 'findobj ('Type ','Line ')'을 사용하여 현재 플롯에있는 행을 가져올 수 있습니다. 비어 있으면 다른 것을 만드시겠습니까? 나는 그것을 지금 시험 할 수는 없지만 그것이 시작 일 수있다. –

답변

0

은 당신이 무엇을 물어 않는 기능입니다 콜린 왈도, 시간 내 주셔서 감사, 자사의 GUI는 코드에서 100 %를 내장 - 희망 당신은 그것에서 아이디어를 얻고 무엇을 변환 할 수 있습니다 원하는 :

function demoVerticalLine 
    % Create the variable which is required to know if the line move is active or not. 
    mouseDown = false; 
    % Create the first value for the xlimMode (used in callbacks) 
    xLimMode = 'auto'; 
    % create a dialog, with the mouse actions set 
    hFig = dialog ('windowstyle', 'normal', 'WindowButtonMotionFcn', @MouseMove, 'WindowButtonUpFcn', @MouseUp); 
    % create an axes 
    ax = axes ('parent', hFig, 'position', [0.1 0.2 0.8 0.7], 'nextplot', 'add'); 
    % create a popup menu 
    pop = uicontrol ('parent', hFig, 'style', 'popupmenu', 'string', { 'sin', 'cos' }, 'Callback', @UpdatePlot); 
    % some dummy data 
    x = -pi:0.01:pi; 
    % an initial X for my example 
    vLineX = randi(length(x)); 
    % On first time through create a plot 
    userPlot = []; % init a value -> this is used to clear the previous user data 
    UpdatePlot(); 
    % get the y limits of the data to be plotted 
    ylim = get (ax, 'ylim'); 
    % plot the vertical line 
    hLine = plot (ax, [x(vLineX) x(vLineX)], ylim, 'ButtonDownFcn', @MouseDown); 
    % a callback for plotting the user data 
    function UpdatePlot (obj, event) 
    % delete any user data which is already plotted 
    delete (userPlot); 
    % plot the user data 
    switch get (pop, 'value') 
     case 1 % sin 
     userPlot = plot (ax, x, sin(x), 'r.-'); 
     case 2 % cos 
     userPlot = plot (ax, x, cos(x), 'b.-'); 
    end 
    end 
    % a function which is called whenever the mouse is moved 
    function MouseMove (obj, event) 
    % only run this section if the user has clicked on the line 
    if mouseDown 
     % get the current point on the axes 
     cp = get (ax, 'CurrentPoint'); 
     % update the xdata of the line handle. 
     set (hLine, 'XData', [cp(1,1) cp(1,1)]); 
    end 
    end 
    % callback from the user clicking on the line 
    function MouseDown (obj, event) 
    % get the current xlimmode 
    xLimMode = get (ax, 'xlimMode'); 
    % setting this makes the xlimits stay the same (comment out and test) 
    set (ax, 'xlimMode', 'manual'); 
    % set the mouse down flag 
    mouseDown = true; 
    end 
    % on mouse up 
    function MouseUp (obj, event) 
    % reset the xlim mode once the moving stops 
    set (ax, 'xlimMode', xLimMode); 
    % reset the mouse down flag. 
    mouseDown = false; 
    end 
end