MATLAB: Unable to load mat file data in Matlab App

load data filesMATLABmatlab app

In the App , I would like to ask the user to select the mat file path and load that file into workspace by pressing a push button. Below is the code and I don't why the mat file data is not getting loaded into the workspace. Secondly I also would like to plot the data in additional tabs. Could somebody help?
% Button pushed function: LoadButton_2
function LoadButton_2Pushed(app, event)
[app.file,app.path] = uigetfile('*.mat');
if isequal(app.file,0)
disp('User selected Cancel');
else
tempX =load(fullfile(app.path,app.file));
app.plotdata_2 =tempX;
disp(['User selected ', fullfile(app.path,app.file)]);
app.Logfile_2EditField.Value = app.file;
end
end

Best Answer

The variables in your mat file are getting loaded into a structure. You have named this structure tempX. In order to access the data, you need to use the structure name and the variable name:
data = tempX.varName;
You can read more about this syntax with load here.