Updating UI figures opened during script: uifigure callback works when figure is opened from command line but not if opened from inside of a script

2 views (last 30 days)
I am trying to run a script that 1) opens up uifigures that have been made and saved out in a previous script, 2) allows the user to interact with checkboxes in the figure, then 3) saves a variable containing which checkboxes were checked. This is for an EEG data analysis pipeline.
My problem is that when I do this from inside of a script or function, user input into the figures does not get saved or updated. It seems the variables that the uifigure is changing are in the Workspace, but do not carry over to inside of the function.
The only way I have gotten it to work so far is to copy/paste the entire script into the command line. From here, after user input into the checkboxes, it correctly saves out a variable in the workspace.
I am basically wondering: is there is anything about uifigures to explain why it might work when opened from command line but not when opened from inside of a function.
In case it is not something to do with uifigures in general, and rather something with the particular uifigures I am using, I attached an example uifigure that I am working with. It is supposed to allow user input to edit the checkboxes, then when pressing the OK pushbutton, the callback should update a variable containing information on which boxes were checked. This callback uses functions from EEGLAB (plugin to analyze EEG data), but the main point is that it saves the guidata.
This information is saved in the attached figure but for reference the callback is:
% Callback: 'data = guidata(gcf); EEG.reject.gcompreject = data.gcompreject; [ALLEEG EEG] = eeg_store(ALLEEG, EEG, CURRENTSET); eegh('[ALLEEG EEG] = eeg_store(ALLEEG, EEG, CURRENTSET);'); close(gcf);'
guidata contains which boxes were checked, and it should update when OK pushbutton is pressed.
Other info: Some of the code used comes from this article https://www.frontiersin.org/articles/10.3389/fnins.2018.00097/full which has code available to download.

Accepted Answer

Walter Roberson
Walter Roberson on 27 Mar 2020
data = guidata(gcf);
That is a callback for use with GUIDE, not for use with uifigure (which is App Designer.)
'data = guidata(gcf); EEG.reject.gcompreject = data.gcompreject; [ALLEEG EEG] = eeg_store(ALLEEG, EEG, CURRENTSET); eegh('[ALLEEG EEG] = eeg_store(ALLEEG, EEG, CURRENTSET);'); close(gcf);'
GUIDE callbacks specified as character vectors are evaluated in the base workspace, not in the workspace of the calling function (because callbacks have no calling function -- callbacks are triggered by events, not by something calling them explicitly.)

More Answers (0)

Categories

Find more on Biomedical Signal Processing in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!