My slider disappears and it comes up with that error
조회 수: 2 (최근 30일)
이전 댓글 표시
I am trying to write a function for having the slider moves according to the mouse wheel. Here is my code
function mouseScroll(~,eventdata,I)
handles = guidata(gcf);
S = round((get(handles.SliderFrame,'Value')));
sno = size(MyMatrix);
UPDN = eventdata.VerticalScrollCount;
S = S - UPDN;
if (S < 1)
S = 1;
elseif (S > sno)
S = sno;
end
if sno > 1
set(handles.SliderFrame,'Value',S);
set(handles.Edit1, 'String', sprintf('Slice# %d / %d',S, sno));
else
set(handles.Edit1, 'String', '2D image');
end
frameindex = max(1, min(S, NumFrames));
handles.frameindex = frameindex+1;
ff = filelist{frameindex};
I=dicomread(ff);
imshow(I, 'parent', handles.axes1);
guidata(hFig,handles);
drawnow()
end
I get the error "Warning: 'slider' control cannot have a 'Value' outside of 'Min'-'Max' range Control will not be rendered until all of its parameter values are valid" when the slider exceeds the maximum value, where it disappears.
Any idea?
댓글 수: 0
채택된 답변
Rik
2018년 6월 8일
Replace
set(handles.SliderFrame,'Value',S);
with
if S>get(handles.SliderFrame,'Max')
S=get(handles.SliderFrame,'Max');
elseif S<get(handles.SliderFrame,'Min')
S=get(handles.SliderFrame,'Min');
end
set(handles.SliderFrame,'Value',S);
댓글 수: 2
Image Analyst
2018년 6월 9일
You can now (>= R2014b) use the more usual "dot" OOP syntax:
sliderValue = handles.SliderFrame.Value;
if sliderValue > handles.SliderFrame.Max
sliderValue = handles.SliderFrame.Max;
elseif sliderValue < handles.SliderFrame.Min
sliderValue = handles.SliderFrame.Min;
end
handles.SliderFrame.Value = sliderValue;
추가 답변 (1개)
Image Analyst
2018년 6월 8일
Put this code in there somewhere:
sliderValue = handles.SliderFrame.Value;
sliderMin = handles.SliderFrame.Min;
sliderMax = handles.SliderFrame.Max;
if sliderValue < sliderMin || sliderValue > sliderMax
% Set slider in the middle.
handles.SliderFrame = (sliderMin + sliderMax) / 2;
% Update value in this function (if we need it later).
sliderValue = handles.SliderFrame.Value;
end
참고 항목
카테고리
Help Center 및 File Exchange에서 Import, Export, and Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!