GUI can't read variable with setappdata and getappdata
古いコメントを表示
I'm working on setappdata and getappdata. My program calls another function within function callback.
function pushbutton1_Callback(hObject, eventdata, handles)
hitung(handles)
d=str2num(get(handles.edit3,'String'));
c=getappdata(handles.pushbutton1,'c2');
set(handles.edit4,'String',c);
while c>d
a=a-1;
c=a/b;
set(handles.listbox1,'String',c);
end
function hitung(handles)
a=str2num(get(handles.edit1,'String'));
b=str2num(get(handles.edit2,'String'));
c=a/b;
set(handles.listbox1,'String',c);
setappdata(handles.listbox1,'c2',c);
I tried edit1 <6>, edit2 <3>, edit3 <1>. But variable c from <c=getappdata(handles.pushbutton1,'c2');> can't display in edit4, and because of that while loops can't run. So the result in listbox1 <2>. Is there any solution? Thankyou.
採用された回答
その他の回答 (1 件)
Yao Li
2013 年 5 月 16 日
0 投票
- The handle for getappdata and setappdata must be the same
- If you write setappdata in the function hitung,you can get data by implementing getappdata only after the function hitung has been called
10 件のコメント
Yao Li
2013 年 5 月 16 日
Why not setappdata under the function listbox1_CreateFcn()?
Yao Li
2013 年 5 月 16 日
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)
hitung(handles.listbox1);
c=getappdata(handles.listbox1,'c2')
function hitung(handles)
c=2;
setappdata(handles,'c2',c);
If you do need the function hitung, try the codes above. I have tested above codes which works well.
Indri Djon Hansemit
2013 年 5 月 16 日
Yao Li
2013 年 5 月 16 日
Indri, I just gave you an example not the exact codes what you want. However, I don't think the while loop will be a problem which is only used to set the value of c. If you do have problems in fixing this and also if it's possible, send them to me.
Yao Li
2013 年 5 月 16 日
And what does 6(a), 3(b),etc. mean?
Indri Djon Hansemit
2013 年 5 月 16 日
Yao Li
2013 年 5 月 16 日
Do u want the listbox only display the final value of c or all the values of a,b,c and d?
Indri Djon Hansemit
2013 年 5 月 16 日
Indri Djon Hansemit
2013 年 5 月 16 日
Indri Djon Hansemit
2013 年 5 月 16 日
カテゴリ
ヘルプ センター および File Exchange で Creating, Deleting, and Querying Graphics Objects についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!