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

60 visualizaciones (últimos 30 días)
Alper
Alper el 1 de Jun. de 2023
Comentada: Alper el 3 de Jun. de 2023
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.

Respuestas (1)

Image Analyst
Image Analyst el 1 de Jun. de 2023
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 comentario
Alper
Alper el 3 de Jun. de 2023
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by