Question about accessing data in GUIDE GUI

1 vue (au cours des 30 derniers jours)
Brian
Brian le 3 Août 2012
So, I recently made a few MATLAB functions through which I can read data, then perform some operations on them (like calculate distances between points, etc).
I can do this fine with a number of functions, but once I tried to make a GUI to make my life a bit easier things got more difficult.
Basically, every time I manipulate data and want to plot the data using a button, I keep on getting a error message saying the data doesn't exist, or rather, it cannot access it. I probably need to nest the data in some way, but I am relatively new to this kind of thing and can really use some advice. I looked at the literature and found this: http://www.mathworks.com/help/techdoc/creating_guis/f13-998449.html#f13-1000157, so I will take a look in the meantime.
Thanks for your help, this is a relatively new field of MATLAB programming for me.

Réponse acceptée

Titus Edelhofer
Titus Edelhofer le 3 Août 2012
Hi Brian,
using nested functions (the link you provided) is in my opinion and godd way, but only if you write the GUI by hand. If you use guide to design your gui, which I would strongly suggest at the beginning, then better use either application data or guidata (the next two paragraphs below your link).
In short: when you read the data, use the function setappdata to store the data, and in another callback use getappdata to access it again.
Titus
  3 commentaires
Titus Edelhofer
Titus Edelhofer le 3 Août 2012
Nearly: to store and read data to the following: suppose your data to be stored is a variable called data1:
% store data1:
handles.data1 = data1;
guidata(hObject, handles);
% read data1 (somewhere else, another callback e.g.):
handles = guidata(hObject);
data1 = handles.data1;
Titus
Brian
Brian le 3 Août 2012
Thanks! This worked out perfectly, I managed to input my data without any problems.

Connectez-vous pour commenter.

Plus de réponses (1)

Azzi Abdelmalek
Azzi Abdelmalek le 3 Août 2012
a simple way to manipulate data is to store them in any of your object using userdata like below:
set(handles.yourobject,'Userdata',data) % data is your data,
% to get your data use
data=get(handles.yourobject,'Userdata) ;
% don't forget to do some conversion because data is a cell.
  1 commentaire
Brian
Brian le 3 Août 2012
Thanks, I will try this later.
If I want to store multiple types of data, and then access those different types for plotting (in my case, I have a set of points and connections) can I store the points and connections in two different userdata cells?
So, maybe something like:
set(handles.yourobject,'Userdata1',data1) % data is your data,
% to get your data use
data=get(handles.yourobject,'Userdata1') ;
% don't forget to do some conversion because data is a cell.
For dataset 1, and then userdata2 for dataset two? Or something along these lines?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Interactive Control and Callbacks 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