MATLAB滑块步骤行为 [英] MATLAB slider step behavior
问题描述
我在MATLAB 2012a中使用GUIDE创建了一个滑块小部件.我希望它控制一个显示图像的轴,其中滑块逐步移动这些图像.
I have a created a slider widget using GUIDE in MATLAB 2012a. I want it to control an axis that displays images inwhich the slider steps through a sequence of them.
我已经在m文件的一部分中为Min,Max和SliderStep设置了滑块的属性.
I have set the slider's properties for Min, Max, and SliderStep in one part of the m-file.
sliderMin = 1;
sliderMax = size(result); % this is variable
sliderStep = [1, 1]; % major and minor steps of 1
set(handles.slider, 'Min', sliderMin);
set(handles.slider, 'Max', sliderMax);
set(handles.slider, 'SliderStep', sliderStep);
set(handles.slider, 'Value', sliderMin); % set to beginning of sequence
在滑块回调中,我已经验证了Min,Max和SliderStep的设置正确.
In the slider callback, I have verified Min, Max, and SliderStep are set correctly.
sliderMin = get(hObject, 'Min') % correct
sliderMax = get(hObject, 'Max') % correct
sliderStep = get(hObject, 'SliderStep') % correct
currentSliderStep = get(hObject, 'Value') % correct, 1 at start
但是,当我单击滑块的箭头时,仅在开始和结束之间跳转.每次将正确的Min,Max,SliderStep和Value(尽管只有1或slideMax)都打印到命令窗口中.我无法以1的增量步进来查看序列内部的图像.
However, when I click on the slider's arrows, I jump only between the beginning and end. Each time the correct Min, Max, SliderStep, and Value (although only 1 or sliderMax) is printed to the command window. I am unable to step in increments of 1 to view the images in the interior of the sequence.
推荐答案
The actual slider step size is scaled by the range: ActualStep = SliderStep * (Max - Min)
The following line should solve your problem: sliderStep = [1, 1] / (sliderMax - sliderMin)
. You should probably check that you don't divide by zero before this line. Do note that sliders won't render if Max
is not greater than Min
.
这篇关于MATLAB滑块步骤行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!