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

33 ビュー (過去 30 日間)
Alper 2023 年 6 月 1 日
コメント済み: Alper 2023 年 6 月 3 日
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 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 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 Center および File ExchangeData Import and Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by