From: Brian on
"Thomas Clark" <t.clark(a)remove.spamcantab.net> wrote in message <grhubq$ph3$1(a)fred.mathworks.com>...
> Bruce,
>
> You can store your data in the 'handles' structure which is passed around the different callbacks.
>
> To do this, make the call to guidata() after you've loaded your data:
>
> function [] = callback_no_1(hObject, eventdata, handles)
>
> % Load your data
> [file path] = uigetfile('.xls');
> data = xlsread([path '/' file]);
>
> % Add your data to the handles structure
> handles.data = data;
>
> % Your data is now in the handles structure. However, this is currently loaded inot a copy of the handles structure which is local to the current callback. To make this handles structure available to all the other callbacks, you need to update the guidata:
> guidata(hObject, handles);
>
> % Your data should be accessible now from a different callback, using:
> function [] = callback_no_2(hObject, eventdata, handles)
> data = handles.data;
>
> Hope this helps!

_______________________________________________________________
Hello,
This is the exact script I'm running in Matlab. I can't get the variable defined in the save callback to be recognised in the load callback. Any idea what's going wrong with it?

Any clarification would be great.

function init(hObject, eventdata, handles)
handles.fig = figure('units','pixels',...
'position',[220 150 400 290],...
'resize','off',...
'name','Two Body Problem',...
'numbertitle','off',...
'color', [0.925,0.914,0.847],...
'menubar','none');

handles.savetext = uicontrol('style','text',...
'position',[10 200 110 15],...
'string','Enter a Number',...
'visible','on',...
'HorizontalAlignment','left');

handles.saveedit = uicontrol('style','edit',...
'position',[90 195 110 30],...
'backgroundcolor','white',...
'enable','on',...
'visible','on');

handles.savepushbutton = uicontrol('style','pushbutton',...
'position',[205 190 110 40],...
'string','Click to Save',...
'visible','on',...
'HorizontalAlignment','left');

handles.loadpushbutton = uicontrol('style','pushbutton',...
'position',[10 100 110 40],...
'string','Click to Load',...
'visible','on',...
'HorizontalAlignment','left');

handles.loadtext = uicontrol('style','text',...
'position',[125 110 110 15],...
'string','Value Entered',...
'visible','on',...
'HorizontalAlignment','left');

set(handles.savepushbutton,'callback',{@save_callback, handles});
set(handles.loadpushbutton, 'callback',{@load_callback, handles});



end

function save_callback(hObject, eventdata, handles)
number=str2num(get(handles.saveedit,'string'));

handles.number=number
guidata(hObject, handles)

msgbox('Variable saved','Saved');

end


function load_callback(hObject, eventdata, handles)
number=handles.number
set(handles.loadtext,'string',num2str(handles.number));

end