MATLAB: Undefined function or variable ‘hObject’ error

app designerguidehobject;

I transfered my guide app to app designe
% Button pushed function: pushbutton1
function pushbutton1_Callback(app, event)
x=get(hObject,'String');
if strcmp(x,'Play')
load_system('equalizer1');
set_param('equalizer1', 'SimulationCommand', 'start');
set(hObject,'String', 'Pause');
else if strcmp(x,'Play')
set_param('equalizer1', 'SimulationCommand', 'pause');
set(hObject,'String', 'Play');
end
end
It opens simulink model that is an equalizer. I got an error
Undefined function or variable 'hObject'.
Error in equal_App_exported/pushbutton1_Callback
x=get(hObject,'String');
I don't really know how to change it, like how to create an hObject in order to make it work properly.

Best Answer

It looks like you've copied and pasted some code from a GUIDE-based app into your App Designer-based app. Don't do that. App Designer doesn't do things the same way. Maybe try something like
commandName = app.edtCommandName.String; % Get user's input from edit field.
if contains(commandName, 'play', 'IgnoreCase', true)
etc.....
end