Katie
Katie

Reputation: 907

In Matlab, how to call GUI callback functions without the GUI?

I am not a GUI programmer, as will become obvious. If anything, I'm trying to unmake a GUI. I am using a program called art (found here, if it's useful to see) that generates figures and variables that I would like to save. You can call art from a batch script and make it read a config file for its inputs, which is what I'm doing, but you have to manually generate and save much of its output (variables and figures) in the GUI. I'd love to automate this process, but I am really struggling.

I think the core of my issue would be solved if I knew how to force the callback functions to be called. For instance, there is a function in art showCorr_Callback(hObject, eventdata, handles) (which is governed by a radio button in the GUI). It has a test condition to execute:

if (get(handles.showCorr,'Value') == get(handles.showCorr,'Max'))

I've tried inserting

mx = get(handles.showCorr,'Max')) 
setappdata(handles.showCorr,'Value', mx) 

into a function I know executes, the opening function, function art_OpeningFcn(hObject, eventdata, handles, varargin). That doesn't seem to have any effect. If I knew how to make the callback functions execute, perhaps I could insert the code that saves the figure into the functions. Somewhere in Matlab's GUI scripts there must be something that is continually testing for a change in state in the GUI. Where is that thing? How can I fool it into thinking a radio button has been pressed?

Thanks for your help, and please let me know if I need to provide more information.

Upvotes: 0

Views: 727

Answers (1)

Suever
Suever

Reputation: 65430

First of all, if you want to set the Value of handles.showCorr, you won't use setappdata as that just stores arbitrary data (by key/value pair) into the graphics object. You actually want to set the Value property.

set(handles.showCorr, 'Value', get(handles.showCorr, 'Max'))

This should trigger any callbacks that are assigned to handles.showCorr.

If, for some reason this doesn't trigger the callback, you can always trigger it manually. If you already know the callback, you can call it explicitly.

showCorr_Callback(hObject, eventdata, handles);

Upvotes: 1

Related Questions