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!