Question about accessing data in GUIDE GUI
1 次查看(过去 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.
0 个评论
采纳的回答
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
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
更多回答(1 个)
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 String 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!