Simultaneous Controlling of image position via slider in MATLAB

时间:2016-08-31 12:16:09

标签: matlab

I am working with multiple images stored in 3D structure in MATLAB. In the first step, I have done the following implementation of slider for controlling of individual images stored in 3D structure:

b(:,:,1)=zeros(300,300);
b(:,:,2)=ones(300,300);
b(:,:,3)=zeros(300,300);
b(:,:,4)=ones(300,300);
b(:,:,5)=zeros(300,300);
smin=1;
smax=5;
hsl = uicontrol('Style','slider','Min',smin,'Max',smax,...
                 'SliderStep',[1 1]./(smax-smin),'Value',1,...
                'Position',[20 20 200 20]);
set(hsl,'Callback',@(hObject,eventdata) imshow(b(:,:,round(get(hObject,'Value')))))

I would like to kindly ask you about implementation of slider controlling simultaneously of two subplots. I need to create a one figure containing of two subplots. The one slider will control both subplots simultaneously. Thank you very much in advance for help.

1 个答案:

答案 0 :(得分:0)

保留每个子图的句柄:

allPlots = [subplot(121) subplot(122)];

然后只需修改你的回调,为每个子图调用imshow,将该子图的句柄作为父轴传递:

set(hsl,'Callback',@(hObject,~) arrayfun(@(thisPlot) imshow(b(:,:,round(get(hObject,'Value'))),'Parent',thisPlot),allPlots))