I have met with a problem when trying loading .MAT file in Matlab GUI with the button callback. The code as follows:
function button1_callback()
[filename,pathname,filterindex]=uigetfile('*.mat','open data');
s1=load (strcat([pathname filename]));
Then, nothing was loaded in the workspace. What can I do to solve this problem? Thanks!
In this case, your statement
s1 = load(...)
requests the result ofload
to be returned as astruct
in the variables1
, see this section of the doc. The variables1
is defined inside the functionbutton1_callback
, and therefore gets destroyed when the execution of that function completes.So, you need to do something to put the data from
s1
where you need it next. If you're programming a UI, you might modify some state of that UI. Or, you could simply push the data into MATLAB's base workspace by usingassignin