accessing data from handles structure from a call back fuction

조회 수: 3 (최근 30일)
Aswathy K V
Aswathy K V 2015년 3월 7일
답변: Adam 2015년 3월 7일
I am new in matlab GUI. The code I have written is as follows:
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%# JDBC connector path
%javaaddpath('C:\DB\mysql-connector-java-5.1.17-bin.jar')
%# connection parameteres
host = 'localhost'; %MySQL hostname
user = 'root'; %MySQL username
password = '';%MySQL password
dbName = 'signature'; %MySQL database name
%# JDBC parameters
jdbcString = sprintf('jdbc:mysql://%s/%s', host, dbName);
jdbcDriver = 'com.mysql.jdbc.Driver';
conn = database(dbName, user , password, jdbcDriver, jdbcString);
if isconnection(conn)
list=get(handles.popupmenu1,'String');
val=get(handles.popupmenu1,'Value');
m=list{val};
qry2 = sprintf('SELECT sign FROM signature where name="%s"',m);
display(qry2);
rs2=fetch(exec(conn, qry2));
alldata2=get(rs2,'Data');
display(alldata2);
qry1 = sprintf('SELECT sign FROM sig_master where name="%s"',m);
display(qry1);
rs1=fetch(exec(conn, qry1));
alldata1=get(rs1,'Data');
display(alldata1);
% delete(handles.figure1)
end
handles.in = alldata2;
handles.master = alldata1;
I want to take data from handles.in and handles.master and assign them to two variables. This process is to be done when push button2 is pressed. Could you pls help me to do this.
function pushbutton2_Callback(hObject, eventdata, handles)

답변 (1개)

Adam
Adam 2015년 3월 7일
You need to add
guidata( hObject, handles );
at the end of your pushbutton1_Callback.
Then in pushbutton2_Callback you can access your data again as
handles.in
handles.master
and do whatever you want with them in the scope of pushbutton2's callback.

카테고리

Help CenterFile Exchange에서 Database Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by