How can I control two axes over a single slider?

2 次查看(过去 30 天)
I have the above code:
handles.SliderFrame = uicontrol('Style','slider','Position',[60 20 400 50],'Min',1,'Max',NumFrames,'Value',1,'SliderStep',[1/NumFrames 2/NumFrames],'Callback',@XSliderCallback);
handles.SliderFrame2 = uicontrol('Style','slider','Position',[60 20 400 50],'Min',1,'Max',sno_s,'Value',slice2,'SliderStep',[1/(sno_s-1) 10/(sno_s-1)],'Callback',@XSliderCallback);
handles.Text1 = uicontrol('Style','Text','Position',[180 420 60 30],'String','Current frame');
handles.Edit1 = uicontrol('Style','Edit','Position',[250 420 100 30],'String','1');
function XSliderCallback(~,~)
handles = guidata(gcf);
%// Here retrieve MyMatrix using getappdata.
MyMatrix = getappdata(hFig, 'MyMatrix');
idx = round((get(handles.SliderFrame, 'Value')));
idx2 = round((get(handles.SliderFrame2, 'Value')));
set(handles.Edit1,'String',num2str(idx));
set(handles.Edit1,'String',num2str(idx2));
filelist = handles.filelist;
frameindex = max(1, min(idx, NumFrames));
handles.frameindex = frameindex+1;
ff = filelist{frameindex};
I=dicomread(ff);
subplot(2,2,1)
image(handles.axes1, I(idx));
imshow(squeeze(I(:,:,idx,:)));
[~, basename, ~] = fileparts(ff);
title( basename);
subplot(2,2,2)
image(handles.axes2, im3(idx2));
imshow(squeeze(im3(:,:,idx2,:)),'XData',[1 592], 'YData',[1 481])
subplot(2,2,3)
image(handles.axes3, im4(idx));
guidata(hFig,handles);
drawnow()
end
It is working. The problem is that I need to modify it somehow that it can alter both axes1 and axes2 the images on them. As it is now, it shows a static image on axes1 and it moves the image in axes2.
I know how to modify it to move the images in axes1, but that means I have to delete several lines for axes2. How can I do it work for both axes at the same time?
  1 个评论
Stelios Fanourakis
Stelios Fanourakis 2018-6-18
OK guys. Here it is. The slice counter shows 1-307 frames, but the correct outcome is from 81-91 frames. Only 10 frames are the way I want them to be. Only 10 out of 307 that the slider runs.
Can you guess why is that?

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2018-6-18
Your sliders are in exactly the same screen position. You create slider2 second so it is on top. Clicks go to the top item only in most circumstances. So the slider on the bottom, slider1, is never receiving clicks to know to update.
  3 个评论
Walter Roberson
Walter Roberson 2018-6-18
axes(handles.axes1)
handles.SliderFrame = uicontrol('Style','slider','Position',[60 20 400 50],'Min',1,'Max',sno_a,'Value',slice3,'SliderStep',[1/(sno_a-1) 10/(sno_a-1)],'Callback',@XSliderCallback);
axes(handles.axes2)
handles.SliderFrame = uicontrol('Style','slider','Position',[60 20 400 50],'Min',1,'Max',sno_s,'Value',slice2,'SliderStep',[1/(sno_s-1) 10/(sno_s-1)],'Callback',@XSliderCallback);
axes(handles.axes3)
handles.SliderFrame = uicontrol('Style','slider','Position',[60 20 400 50],'Min',1,'Max',sno_c,'Value',slice1,'SliderStep',[1/(sno_c-1) 10/(sno_c-1)],'Callback',@XSliderCallback);
You overwrite handles.SliderFrame twice. The positions of all of them are exactly the same.
Position coordinates for a uicontrol are not relative to axes, they are relative to the parent uipanel, uitab, or figure.
Stelios Fanourakis
Stelios Fanourakis 2018-6-18
I see. You probably are right. Can you please suggest me a way to have a slider and control three axes in synchronization?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by