필터 지우기
필터 지우기

Question about accessing data in GUIDE GUI

조회 수: 1 (최근 30일)
Brian
Brian 2012년 8월 3일
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에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by