Load function in script not saving to Workspace

조회 수: 17 (최근 30일)
Naren Divvala
Naren Divvala 2018년 5월 1일
편집: Stephen23 2018년 5월 2일
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');

답변 (1개)

Stephen23
Stephen23 2018년 5월 2일
편집: Stephen23 2018년 5월 2일
"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.

카테고리

Help CenterFile Exchange에서 .NET Data Types in MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by