How to load .mat file to base workspace using App Designer?

37 次查看(过去 30 天)
Hey, I would like to load a .mat file to workspace using buttonpushed callback function:
When I pushed the button uigetfile function will run and I will choose the mat file that I want to load it to base workspace.
[file,path] = uigetfile('*.m','Choose File');
data = load([path,file]);
The .mat file is loading into app.data struct but it could not read from workspace.

回答(1 个)

Image Analyst
Image Analyst 2023-6-1
It's usually not a good idea to load variables into the base workspace. It's best if you just load it into your program as a global variable hanging off the app structure.
[baseFileName, folder] = uigetfile('*.m','Choose File');
fullFileName = fullfile(folder, baseFileName)
app.storedDataStructure = load(fullFileName)
Why do you think you want/need it in the base workspace instead of only in the scope of your program?
Don't use path as the name of your variable since it's the name of an important built-in global variable.
Also, it might be good to pre-load all the .mat files into a drop down list or a listbox. Much friendlier to the user.
  1 个评论
Alper
Alper 2023-6-3
The reason why I want the data selected by the user to also appear in the base workspace is because I want the user to be able to use the application and the command window at the same time. However, you are right, this may cause it to fall out of the scope of my application. Thanks for your answer.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by