I am working on an app in GUIDE matlab. I want to display some information (1st cell in a field of a structure) in an editbox in the main figure of GUI. I was using the followinf code, which doesn't work (no change to the edit text box):
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
MyData=handles.MyData;
handles.edit1 = edit1;
name=MyData.XXX.subsysNames(1,1)
set(handles.edit1,'String',cell2str(name));
guidata(hObject, handles)
(I suspect that I might be using the handles wrong but I am not sure. Could somebody point me in the right direction? ) How do I update the edit box?
Thanks!

 채택된 답변

Dennis
Dennis 2019년 7월 24일

0 개 추천

Do you get any error messages?
You are overwriting the handle of your edit box, thus you use the wrong handle when you try to update it:
handles.edit1 = edit1; % this should throw an error unless you have an edit1 function somewhere
edit1=handles.edit1; %this would be okayish, but not necessary
I am not aware of any cell2str function. Here is a small example what might work:
handles.MyData{1}=123;
handles.edit1=uicontrol('style','edit');
set(handles.edit1,'callback',{@edit1_cb,handles})
function edit1_cb(hObj,~,handles)
set(handles.edit1,'string',num2str(handles.MyData{1}))
%set(hObj,'string',num2str(handles.MyData{1})) %this would work aswell
end

댓글 수: 5

Wiktoria Glogowska
Wiktoria Glogowska 2019년 7월 24일
I am not getting any error message.
handles.edit1 = edit1; doesn't give me any errors either
Still after applying your suggestion the edit text box isn't updated. Maybe I am using it wrong... is the function edit1_cb supposed to be embedded in function edit1_Callback(hObject, eventdata, handles) or directly after?
Dennis
Dennis 2019년 7월 24일
Actually it is a replacement.
I think your callback might not trigger, to trigger the callback of an edit box place the cursor inside the box and press 'enter'.
Wiktoria Glogowska
Wiktoria Glogowska 2019년 7월 24일
편집: Wiktoria Glogowska 2019년 7월 24일
It worked when I changed cell2str to cellstr and pressed Enter. So my question now is why it was be not triggered? What to do to trigger the callback without pressing ENTER? I would like loading of the data (different callback function) to be the 'triggering event' for the text to appear (immediately once the data is loaded the edit box is filled).
Dennis
Dennis 2019년 7월 24일
In that case you can simply change the text of the edit field inside the callback that loads your data.
Wiktoria Glogowska
Wiktoria Glogowska 2019년 7월 24일
Thanks for help!!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

질문:

2019년 7월 24일

댓글:

2019년 7월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by