accessing data from handles structure from a call back fuction
5 次查看(过去 30 天)
显示 更早的评论
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)
0 个评论
回答(1 个)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Database Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!