Question about accessing data in GUIDE GUI

2 次查看(过去 30 天)
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.

采纳的回答

Titus Edelhofer
Titus Edelhofer 2012-8-3
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 个评论
Titus Edelhofer
Titus Edelhofer 2012-8-3
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 2012-8-3
Thanks! This worked out perfectly, I managed to input my data without any problems.

请先登录,再进行评论。

更多回答(1 个)

Azzi Abdelmalek
Azzi Abdelmalek 2012-8-3
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 个评论
Brian
Brian 2012-8-3
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?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 String 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by