2016-04-09 16 views
0

GUIDEの関数qrsdet(vecParam1,scaParam1,scaParam2)を押しボタンstartAnalysisを使用して呼び出しようとしています。Matlab GUIプッシュボタンを使用して関数を呼び出す

GUIのCODE:

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

handles.output = hObject; 
guidata(hObject, handles); 

------- 
% remaining GUI code 
------- 

% pushbutton code to call function 
function qrsdetfn_Callback(hObject, eventdata, handles) 

hr = qrsdet(vecArg1,scaArg1,scaArg2); 
textLabel = sprintf('%.2f', hr); 
set(handles.heartratetext, 'String', hr); 
guidata(hObject,handles) 

私は私のGUIと同じディレクトリに存在qrsdet.mと呼ばれる.mファイルを、定義している。ここのコードです。 3つの引数はすべて、GUIを使用してユーザーから取得されます。私はMATLABのGUIでhandles構造にvecArg1を格納している

Undefined function or variable 'vecArg1'. 

:私は、私はエラーを取得する私の関数に引数を渡す際に問題があります。私も次のステートメントを使用して試してみた:

qrsdet(handles.vecArg1,scaArg1,scaArg2) 

が、これはエラーを返します:

Reference to non-existent field 'vecArg1' 

これは私がvecArg1

% --- Executes on button press 
function pushbtnForvecArg1_Callback(hObject, eventdata, handles) 

handles.fileloc = get(handles.filelocation,'String'); 
fileID = fopen(handles.fileloc); 
handles.vecArg1 = fscanf(fileID,'%f',inf); 
assignin('base','vecArg1',handles.vecArg1); 
guidata(hObject,handles) 

をロードするために使用しているプッシュボタンである私が」 MatlabのGUIデザインにはまったく新しいものですが、何が問題なのかを指摘していますか?

+0

は、あなたの質問に関連する情報のすべてを含める必要があります...GUIの 'handles'構造体に' vecArg1'を保存したとします。 * *と* *あなたはこれをやっていますか? – excaza

+0

@excaza – inSearchofAnswers

答えて

1

私は入力パラメータが問題だと思います。

MATLABで関数を開始するときは、変数に値を割り当てる必要があります。 MATLAB GUIDEでは、vecArg1、vecArg2、およびvecArg3を使用した場合に変数を使用することはできません。基本的に、存在しない変数を使用したと考えます。

私は次のコードが役に立つと思います。

setappdata(hObject.Parent, 'vecArg1', desired_value_to_be_stored); 

をこれは、あなたがこのデータを取得するために、ガイドファイルの異なるセクションに次のコードを使用できるようになります:使用して変数を設定し

data_to_be_used = getappdata(hObject.Parent, 'vecArg1'); 

それは少し面倒ですが、それは動作するはずです。

~~~~~~~~~~~~~~~~~~~~~~~~

EDIT1:関数setappdataとgetappdataを

GUIDE M-ファイルの使用の実証、 figurecontains:

pushbutton1 - > &テストデータを取得

pushbutton2 - >データセット

ボタンを押して上と呼ばれる210
function varargout = gui_example(varargin) 
% GUI_EXAMPLE MATLAB code for gui_example.fig 
%  GUI_EXAMPLE, by itself, creates a new GUI_EXAMPLE or raises the existing 
%  singleton*. 
% 
%  H = GUI_EXAMPLE returns the handle to a new GUI_EXAMPLE or the handle to 
%  the existing singleton*. 
% 
%  GUI_EXAMPLE('CALLBACK',hObject,eventData,handles,...) calls the local 
%  function named CALLBACK in GUI_EXAMPLE.M with the given input arguments. 
% 
%  GUI_EXAMPLE('Property','Value',...) creates a new GUI_EXAMPLE or raises the 
%  existing singleton*. Starting from the left, property value pairs are 
%  applied to the GUI before gui_example_OpeningFcn gets called. An 
%  unrecognized property name or invalid value makes property application 
%  stop. All inputs are passed to gui_example_OpeningFcn via varargin. 
% 
%  *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one 
%  instance to run (singleton)". 
% 
% See also: GUIDE, GUIDATA, GUIHANDLES 

% Edit the above text to modify the response to help gui_example 

% Last Modified by GUIDE v2.5 10-Apr-2016 15:17:00 

% Begin initialization code - DO NOT EDIT 
gui_Singleton = 1; 
gui_State = struct('gui_Name',  mfilename, ... 
        'gui_Singleton', gui_Singleton, ... 
        'gui_OpeningFcn', @gui_example_OpeningFcn, ... 
        'gui_OutputFcn', @gui_example_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 gui_example is made visible. 
function gui_example_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 gui_example (see VARARGIN) 

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

% Update handles structure 
guidata(hObject, handles); 

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


% --- Outputs from this function are returned to the command line. 
function varargout = gui_example_OutputFcn(hObject, eventdata, handles) 
% varargout cell array for returning output args (see VARARGOUT); 
% hObject handle to figure 
% eventdata reserved - to be defined in a future version of MATLAB 
% handles structure with handles and user data (see GUIDATA) 

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


% --- Executes on button press in pushbutton1. 
function pushbutton1_Callback(hObject, eventdata, handles) 
% hObject handle to pushbutton1 (see GCBO) 
% eventdata reserved - to be defined in a future version of MATLAB 
% handles structure with handles and user data (see GUIDATA) 

status = printvector(getappdata(hObject.Parent, 'vecArg1')); 

disp(status); 

% --- Executes on button press in pushbutton2. 
function pushbutton2_Callback(hObject, eventdata, handles) 
% hObject handle to pushbutton2 (see GCBO) 
% eventdata reserved - to be defined in a future version of MATLAB 
% handles structure with handles and user data (see GUIDATA) 


%Set vector argument 
vectorArgument1 = [1.001; 1.002; 1.003; 1.004]; 
setappdata(hObject.Parent, 'vecArg1', vectorArgument1); 

機能:

function [ status ] = printvector(vec1) 
    disp('I am in the function') 
    for i = 1:length(vec1) 
     disp(vec1(i,1)); 
    end 

    status = 'success'; 
end 
+0

の値をロードするために使用される押しボタンを含むように更新されました。データを取得する行で '構造化されていない配列の参照フィールドへの試み 'を返します。 – inSearchofAnswers

+0

「vecArg1」の内容の例を教えてもらえますか? – DeeCee

+0

これは二重の値からなる列ベクトルです – inSearchofAnswers

関連する問題