MATLAB: Add to listbox in GUI from .mat file

guilistboxmatvarargin

My GUI currently has 3 push buttons and a list box. two buttons calls for the user to choose their desired data file. these data files all have the same format, however they have a different number of data sets. in the GUI when i press the pb2, it saves all the variables used that were calculated. i would like to use one of the variables which has X ammount of data set, and read that data, and write that data to the list box. here is the code i tried, i get errors about the structure and i'm quite stumped. I'm following GUIs_FEX GUI layouts and creating from the base up because I don't really understand how to do calculations in the GUIDE file. it tells me variables don't exist, and variables wiped out every function. If somone has time to discuss with me and help me that would be great, thank you!
S.ls = uicontrol('style','list','unit','pix','position',[50 50 150 450],...
'min',0,'max',2,'string','Frequencies','callback',{@ls_call});
.
.
.
load('F06_Variables')
for i=1:R
S= varargin{3}
oldstr = get(S.ls,'string');
addstr = {frequency(i)};
set(S.ls,'str',{oldstr{:},addstr{:}});
end

Best Answer

I think the main issue is that the variables only has local scope when loaded in a callback function. If you only have one GUI, the easiest way to access data when you jumping in and out functions is using GUIDATA for the specific items. For example, set your data as the guidata of the whole GUI:
s=load('F06_Variables');
guidata(figure_handle,s); %remember to update the guidata every time you load a new .mat file
%%%%%%%%%%in pushbutton or listbox callbacks
S=guidata(figure_handle); %you can add 'figure_handle' as an input for the callbacks, or obtain it by get(hObject,'Parent') if figure is the parent of pushbutton or listbox
And there're other ways also available for your purpose, details on the link below: http://www.mathworks.cn/cn/help/matlab/creating_guis/ways-to-manage-data-in-a-programmatic-gui.html
Related Question