Info

此问题已关闭。 请重新打开它进行编辑或回答。

Could nt get the result

1 次查看(过去 30 天)
Sandhiya CSE
Sandhiya CSE 2020-5-17
关闭: MATLAB Answer Bot 2021-8-20
f=figure;
c=uicontrol;
c.String='getrsf';
function getrsf_Callback(hObject, eventdata, handles)
% hObject handle to msg_box (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
demo;
end

回答(1 个)

Walter Roberson
Walter Roberson 2020-5-17
c.Callback = @(s,e) getrsf_Callback(s, e, guidata(s))
That is to say, the String property of a uicontrol has no effect on callbacks: it is what the uicontrol displays.
When you create a gui using Guide then one of the things it does for you is to link in callbacks on your behalf. It does that by setting the Callback (or appropriate) property of the graphics objects saved in the fig file.
It also links the graphic object into handles on your behalf. It does that at the time it loads the gui by looking for Tag properties of graphic objects and creating fields in the handles structure for each valid Tag.
Note that these are two separate processes: callbacks saved as part of the object properties, and glue logic when the gui initializes that creates handles according to Tag.
When you create a graphics object yourself you need to set the callback property yourself. If you want you can also add the item into the handles structure.
  3 个评论
Walter Roberson
Walter Roberson 2020-5-17
c.Callback = @(hObject, eventdata) getrsf_Callback(hObject, eventdata, guidata(s))
shuld i replace your given line with that function i my code
No, this code is what is needed if you want to invoke your
function getrsf_Callback(hObject, eventdata, handles)
as a callback. Only change it if you name your callback something different.
Note: you will also want to set the Position property of your uicontrol.
Image Analyst
Image Analyst 2020-5-17
Sandhiya, Did you just cut and paste small snippets of an application you'd created in GUIDE? If so, attach the .m and .fig file. Or is that your whole program?

此问题已关闭。

Community Treasure Hunt

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

Start Hunting!

Translated by