populate a listbox in a GUIDE gui through a function call from a Matlab script (.m file)

3 visualizzazioni (ultimi 30 giorni)
While Im quite comfortable with functions and scripts in matlab, this is my first time venturing into GUIDE guis. I created a figure containing a listbox, a drop down list as well as a plot. The idea is to call this gui from a Matlab script under certain conditions, populating the listbox with a list of files. The user would select a plot "profile" from the drop down list which will then select the appropriate plots to show.
At this point Im struggling with just getting the listbox to update properly. I saved my gui generated from GUIDE as svt_plotter, which I call from my script with:
H= svt_plotter({'A','B'});
In the svt_plotter.m file I added the following line in svt_plotter_OpeningFcn just before the call to update handles structure: handles.list = varargin{1}; %save the input argument to be used in the listbox function later. This is a straight call right now with no logic to see if it works
finally I added this line to update the listbox under listbox1_CreateFcn set(hObject, 'String', handles.list);
When I do this I get an error 'Attempt to reference field of non-structure array.'. Replacing the handles.list with the explicit cell array works just fine. What am I missing here?
Any good reference document that can help in understanding GuIDE code and how to interact with it would be much appreciated.

Risposta accettata

PG_Dev
PG_Dev il 21 Nov 2017
Modificato: PG_Dev il 24 Nov 2017
Mohammed,
Remove handles.list = varargin{1} and put this line in svt_plotter_OpeningFcn
set(handles.listbox1, 'String', varargin{1});
Remove set(hObject, 'String', handles.list) from the listbox opening function. Its throwing that error because 'handles' is an empty array in the listbox opening function argument and not the 'handles' from the svt _plotter opening function.
Best Regards
PG
  3 Commenti
PG_Dev
PG_Dev il 22 Nov 2017
Mohammed,
As I've mentioned in my answer before please put the statement in the svt_plotter_OpeningFcn and not in the listbox1_CreateFcn. It will work. From your error message Error in svt_plotter>listbox1_CreateFcn (line 191) it appears that you put the statement in the listbox1_CreateFcn.
-PG
Mohammed
Mohammed il 23 Nov 2017
Thank you very much! That worked... I also found this which is really helping me get a grasp on how this all works:
https://www.mathworks.com/help/matlab/creating_guis/share-data-among-callbacks.html

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by