How to create a callback from a function which changes a value in another function?

1 次查看(过去 30 天)
Doing some Image processing, I have a slider on my figure which will change my Field of View or zoom of the images.
Function Startup
-hidden-
ImageProperties(fov,Plot)
-hidden-
FOV = 30; %Field of view
%% FOV Slider
uicontrol('Style','slider',...
'Min',40,'Max',80,'Value',50,...
'SliderStep',[1 10]/40,... %Slider Increases in Increments of one
'Position', [500 875 100 20],...
'Callback',{@Slider});
- hidden -
end
function Slider(hObj,event)
fov = get(hObj,'Value');
end
function ImageProperties(fov,Plot)
-hidden-
set(Plot,'xlim'[-fov fov]
end
end
Basically I wsnt the slider to change the value of FOV and update all my images with the new FOV set by the slider.
ps Sorry for all the hidden code hope people can still help!

采纳的回答

Iain
Iain 2013-5-21
Add: ImageProperties(fov,Plot) to your slider callback... obviously you'll need to supply fov and Plot.
  2 个评论
Hanif
Hanif 2013-5-21
lain thanks but it didn't work! Maybe I am doing something wrong.
uicontrol('Style','slider',...
'Min',40,'Max',80,'Value',50,...
'SliderStep',[1 10]/40,... %Slider Increases in Increments of one
'Position', [1010 765 20 120],...
'Callback',{@Slider,ImageProperties(fov,Plot)});
FOV is pre-defined above in the start up function so is Plot.
Jan
Jan 2013-5-22
I assume, lain meant the code of the callback. The value of fov is updated in the slider's callback, but then the callback returns and the value of fov is not used anywhere. So either use it directly from inside the sliders callback, or store the fov value e.g. by GUIDATA, such that the ImageProperties function can obtain it afterwards.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by