Load function in script not saving to Workspace

3 views (last 30 days)
I have a nueral network saved in a mat file- Net.Mat, I want to load this network, so I've put the load function in a pushbutton call back. However, when I click on the button, the network isnt showing up in the workspace. When I double click on the Net.mat file, my network shows in the workspace. But not when the load function is executed as a part of the code for my pushbutton.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
load Net;
handles.net=net;
set(handles.pushbutton3,'Enable','on');
set(handles.pushbutton5,'Enable','on');

Answers (1)

Stephen23
Stephen23 on 2 May 2018
Edited: Stephen23 on 2 May 2018
"However, when I click on the button, the network isnt showing up in the workspace"
Yes it is. It will be loaded into the callback workspace. Every function (and this includes callback functions) have their own independent workspace. So when you load into that workspace, that is where you can find it. If you want to pass that data into another workspace, then you will need to pass that data, as is explained in the MATLAB documentation:
You should use guidata, something like this:
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
S = load('Net.mat');
handles.net = S.net;
set(handles.pushbutton3,'Enable','on');
set(handles.pushbutton5,'Enable','on');
guidata(hObject,handles) % you need this line!
end
And then the field .net will be available anywhere where you can access handles.

Community Treasure Hunt

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

Start Hunting!