MATLAB GUI; after having loaded a .mat file, how do I remove tht data form my workspace to open a different .mat file?

1 vue (au cours des 30 derniers jours)
I just started messing with the GUI today and so far I have been pretty successful. I know how to make things such as push buttons and that by using uiopen('load') I can prompt the user to select a .mat file to be loaded to run data analysis however my predicament is this: how do I remove the old data so that I can run an analysis on the new data, or is it possible to keep both loaded and be able to compare the different data? For example would I assign a variable like data1=uiopen('load') and then when the user wants to load another .mat file do data2=uiopen('load')?
I assume it loads the file to a work space however since I only have a few months experience in MATLAB I am still unsure as to how this stuff works in a GUI.
Thanks!

Réponses (1)

Jan
Jan le 28 Jan 2017
It is a good programming practice not to pollute the base workspace with data, because this suffers from the same problems as global variables (search for "programming global problem" for more details). It is much better to store the imported variables inside the GUI, then you can open multiple GUIs without the danger of interferences.
Storing the data inside a GUI is discussed frequently in this forum, search e.g. for "share data between callbacks GUI": Use guidata, set/getappdata or set(FigHandle, 'UsersData'). Then start the processing using a "Start" button, whose callback obtains the data from the GUI and provide it as inputs to the function (not script) for the calculations.
Using this method, you can import several data sets easily, by storing them e.g. in a cell array:
% During the construction of the GUI:
set(FigH, 'UsersData', {});
% In the callback for importing:
data = get(FigH, 'UserData');
newData = uiopen('load'); % Or whatever
data{length(data) + 1} = newData;

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by