0

GUIの外にある関数を使おうとしています。これは.mファイルであり、handles.axes6とhandles.axes7であるGUIコンポーネントを更新したいと思います。以下は、GUImファイルのスクリプトです。

function pushbutton8_Callback(hObject, eventdata, handles)

h1 = handles.axes6; 
h2 = handles.axes7;

mousemotion(h1,h2);

機能コード(GUI外)

function mousemotion(click)
 global rdata;
 nargin<1
   set(gcf,'WindowButtonDownFcn','mousemotion(''down'')');
   set(gcf,'WindowButtonUpFcn','mousemotion(''up'')');
   set(gcf,'WindowButtonMotionFcn','');
   axis vis3d
4

1 に答える 1

0

GUI Opening関数内で、GUIハンドルとAxesハンドルをエクスポートし、次のように必要な関数からそれらを取得します。

function figure_OpeningFcn(hObject, eventdata, handles,varargin)

%// This function has no output args, see OutputFcn.
%// hObject    handle to figure
%// eventdata  reserved - to be defined in a future version of MATLAB
%// handles    structure with handles and user data (see GUIDATA)
%// varargin   command line arguments to DatabaseViewerApp (see VARARGIN)

%// Choose default command line output for DatabaseViewerApp
handles.output = hObject;

%// Update handles structure
guidata(hObject, handles);
%// UIWAIT makes DatabaseViewerApp wait for user response (see UIRESUME)
%// uiwait(handles.mainFigure);

    %//set the current figure handle to main application data
    setappdata(0,'figureHandle',gcf);

    %//set the axes handle to figure's application data
    setappdata(gcf,'axesHandle1',handles.axes6);

    %//set the axes handle to figure's application data
    setappdata(gcf,'axesHandle2',handles.axes7);

end

次に、任意の関数func1で、それらを次のように使用します。

function varargout = func1(varargin)

%// get the figure handle from the application main data
figureHandle = getappdata(0,'figureHandle');

%// get the axes handle from the figure data
axesHandle1 = getappdata(figureHandle,'axesHandle1');

%// get the axes handle from the figure data
axesHandle2 = getappdata(figureHandle,'axesHandle2');

%// And here you can write your own code using your axes

end
于 2013-01-08T12:35:40.920 に答える