I need some help with Undefined function 'plot_button_Callback' for input arguments of type 'struct'.

1 visualización (últimos 30 días)
I have two logged data files each one contains a time array and an engine speed array. They are in the base work space as a b c d as 2138x1 doubles. I want to pass a b c d into a function so that the user can plot them and time align the two data sets by shifting the second time array with an offset typed into an input box. So I grabbed the two_axes example and edited it to get the following function and nested functions (I nested them so that a b c d would be available ti the sub functions). I call timealign from my main m file like this timealign(a, b, c, d); Where a is time array 1, b is rpm array 1, c is time array 2 and d is rpm array 2.
The problem is that when I push the plot button in the gui I get this error "Undefined function 'plot_button_Callback' for input arguments of type 'struct'." and I just can't understand how to fix this and make it work so I can't get any further with developing the code to do the time aligning or test it. I am not passing a b c d in as structures just as arrays so I don't understand the error.
I struggle with the "object orientated" type coding so if you give answer please provide an edited version of the code rather than a verbal explanation which i might not understand enough to implement successfully. I have attached the 3 files.
Thanks in advance for any help
function varargout = timealign(varargin)
%TIMEALIGN M-file for timealign.fig
% TIMEALIGN, by itself, creates a new TIMEALIGN or raises the existing
% singleton*.
%
% H = TIMEALIGN returns the handle to a new TIMEALIGN or the handle to
% the existing singleton*.
%
% TIMEALIGN('Property','Value',...) creates a new TIMEALIGN using the
% given property value pairs. Unrecognized properties are passed via
% varargin to timealign_OpeningFcn. This calling syntax produces a
% warning when there is an existing singleton*.
%
% TIMEALIGN('CALLBACK') and TIMEALIGN('CALLBACK',hObject,...) call the
% local function named CALLBACK in TIMEALIGN.M with the given input
% arguments.
%
% *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 timealign
% Last Modified by GUIDE v2.5 14-Jan-2015 09:14:03
InputArgs = (varargin);
a = varargin{1};
b = varargin{2};
c = varargin{3};
d = varargin{4};
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @timealign_OpeningFcn, ...
'gui_OutputFcn', @timealign_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 timealign is made visible.
function timealign_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 unrecognized PropertyName/PropertyValue pairs from the
% command line (see VARARGIN)
% Choose default command line output for timealign
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes timealign wait for user response (see UIRESUME)
% uiwait(handles.figure1);
end
% --- Outputs from this function are returned to the command line.
function varargout = timealign_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;
end
function time2offset_input_Callback(hObject, eventdata, handles)
% hObject handle to time2offset_input (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of time2offset_input as text
% str2double(get(hObject,'String')) returns contents of time2offset_input as a double
% Validate that the text in the time2offset field converts to a real number
time2offset = str2double(get(hObject,'String'));
if isnan(time2offset) || ~isreal(time2offset)
% isdouble returns NaN for non-numbers and time2offset cannot be complex
% Disable the Plot button and change its string to say why
set(handles.plot_button,'String','Cannot plot time2offset')
set(handles.plot_button,'Enable','off')
% Give the edit text box focus so user can correct the error
uicontrol(hObject)
else
% Enable the Plot button with its original name
set(handles.plot_button,'String','Plot')
set(handles.plot_button,'Enable','on')
end
end
% --- Executes on button press in plot_button.
function plot_button_Callback(hObject, eventdata, handles)
% hObject handle to plot_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get user input from GUI
time2offset = str2double(get(handles.time2offset_input,'String'));
% Calculate data
newtime = b + time2offset;
% Create time plot in axes
plot(handles.time_axes, a, c)
plot(handles.time_axes, newtime, d)
end
end

Respuesta aceptada

Geoff Hayes
Geoff Hayes el 16 de En. de 2015
Andrew - I've never had much luck passing data in this manner to the GUI (using GUIDE) so I'm not really sure if this is something that is allowed/encouraged or (if it is) what the proper syntax is, though I suspect the problem might be related to the fact that you have nested your functions within the m file. I recommend that you remove the nesting (so the end from each function) and take the code that you put in the timealign function (which shouldn't be edited) and move it to the timealign_OpeningFcn as
function timealign_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 unrecognized PropertyName/PropertyValue pairs from the
% command line (see VARARGIN)
time1 = varargin{1};
rpm1 = varargin{2};
time2 = varargin{3};
rpm2 = varargin{4};
% Choose default command line output for time align
handles.output = hObject;
handles.time1 = time1;
handles.rpm1 = rpm1;
handles.time2 = time2;
handles.rpm2 = rpm2;
% Update handles structure
guidata(hObject, handles);
Now, all your data is saved to the handles structure (and it is save only after the call guidata(hObject,handles) is made) and all of your callbacks can access this data because they receive the handles object as an input parameter.
Your push button callback can now make use of this data from handles as
function plot_button_Callback(hObject, eventdata, handles)
% hObject handle to plot_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get user input from GUI
time2offset = str2double(get(handles.time2offset_input,'String'));
% Calculate data
newtime = handles.time2 + time2offset;
% Create time plot in proper axes
plot(handles.time_axes, handles.time1, handles.rpm1)
plot(handles.time_axes, newtime, handles.rmp2)
I've guessed at the above because your definitions for a, b, c and d didn't seem to match how you were using them, but you get the idea.
Try the above and see what happens!
  5 comentarios
Geoff Hayes
Geoff Hayes el 22 de En. de 2015
Andrew - in GUIDE, open the property inspector for each of these new text boxes. You should notice that in the CreateFcn property for each, there is a callback defined, yet you don't have the callback in your m file. The GUI expects a callback, but none can be found and so the errors are thrown. Either delete these callbacks (through the property inspector) or just add the following lines to your m file
function t0_input_CreateFcn(hObject, eventdata, handles)
function t1_input_CreateFcn(hObject, eventdata, handles)
function x1_input_CreateFcn(hObject, eventdata, handles)
function x0`_input_CreateFcn(hObject, eventdata, handles)
Andrew Tilmouth
Andrew Tilmouth el 23 de En. de 2015
Thanks Geoff, I didn't realise these had been created in the GUI by Guide. works fine now, thanks Andrew

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by