0

私のプログラムは、ファイルからデータをロードしてグラフを生成します。ユーザーが関心のある領域をクリックすると、分析が行われ、新しいグラフが生成されます。プログラムは、ユーザーがプログラムを終了するために押すまで、ユーザーに画像をクリックするように求め続けますe

生成されるグラフを、プログラムからデータを取得する GUI にしたいのですが、そのデータを GUI 関数に転送するのに問題があるようです。私のプログラムがどのように見えるかの簡単な例を次に示します。

load(data)
plot(x,y)
while 1%so that it continues asking for user interaction
     figure(1)
     'click on the point you want or press e to exit'
     [x1,y1,key]=ginput(1)

     f=score(x1,y1)
     %the above is a different function that gives us the data that I want to graph,
     %that are called xf,yf 

     %GUI plot
     figure(1)
     test_gui(xf,yf)

     if (key == 'e')
     display('End')
     break;
     else
     display('next point')
     end
end

test_gui.mはこのように見えます:

function varargout = test_gui(varargin)
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
               'gui_Singleton',  gui_Singleton, ...
               'gui_OpeningFcn', @test_gui_OpeningFcn, ...
               'gui_OutputFcn',  @test_gui_OutputFcn, ...
               'gui_LayoutFcn',  [] , ...
               'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before fft_guide is made visible.
function test_gui_OpeningFcn(hObject, eventdata, handles, varargin)


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

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes test_gui wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = test_gui_OutputFcn(hObject, eventdata, handles) 

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
plot (xf,yf)   

問題は、「プッシュ」ボタンをクリックしても何もグラフに表示されないためxfyf変数を渡す方法に問題があるはずです。私が間違っていることについて誰かが何か考えを持っているかどうか疑問に思っていました.私は以前にGUIDEを使用したことがなく、迷っているようです.

4

1 に答える 1

0

コードの外観から、xfyfは決して定義されず、f( の結果score) のみです。そのため、プロットが表示されない可能性があります。

Werner がコメントしたように、ワークスペースにscoreダンプするxfと仮定するとyf、最初にそれらを定義してからvarargin、を使用してコールバック関数に渡す必要があります。handles

% --- Executes just before fft_guide is made visible.
function test_gui_OpeningFcn(hObject, eventdata, handles, varargin)
xf = varargin{0}; yf = varargin{1}; % Get xf and yf from input
handles.xf = xf; handles.yf = yf;  % Put the values in handles
guidata(hObject,handles);   % Save handles so you can use it anywhere in the GUI

そしてコールバックで:

% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
plot (handles.xf,handles.yf)

GUI関数に渡される前に正しく定義されていると仮定するxfと、これは機能するはずです。yf

于 2013-09-11T18:47:32.690 に答える