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

조회 수: 1 (최근 30일)
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.

채택된 답변

PG_Dev
PG_Dev 2017년 11월 21일
편집: PG_Dev 2017년 11월 24일
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
PG_Dev
PG_Dev 2017년 11월 22일
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 2017년 11월 23일
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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by