在MATLAB中使用连续滑块的值 [英] Use the value of continuous slider in MATLAB
问题描述
我只想要去,就是在我滑块中使用连续的滑块值,因为我滑动滑块。但是,我无法弄清楚如何提取滑块的值。
所以,例如,创建一个连续的滑块,然后使用它来改变向量的幅度,就像你连续滑动它。如何做?
谢谢。
这个?
function sliderDemo
f = figure(1);
%//一些简单的绘图功能(带可调参数)
x = 0:0.1:2 * pi;
y = @(A)A * sin(x);
%//设置初始情节
A = 1;
p = plot(x,y(A));
轴紧
轴([0 2 * pi -10 10])
%//重新定位轴为滑块腾出空间
set gca,'position',[0.1 0.25 0.85 0.7]);
%//初始化滑块
h = uicontrol(...
'parent',f,...
'units','normalized' ..%//所以你不必f * ck与像素
'style','slider',...
'position',[0.05 0.05 0.9 0.05],...
'min',1,...%//使A在1 ...
'max',10,...%//和10之间,初始值
'value',A,...%//如上所述
'callback',@sliderCallback); %//当使用箭头
%//和/或单击滑块时调用
%// THE MAGIC INGREDIENT
%// =======================
hLstn = handle.listener(h,'ActionEvent',@ sliderCallback) ; %#OK< NASGU>
%//(变量未使用,但不分配给任何东西意味着
%//监听器存储在'ans'变量中,如果ans被覆盖,
% //听众超出范围,因此被破坏,因此,它没有
%//更长的工作
%// =========== ================
%//滑块的回调:
%// 1)清除旧图
%// 2)使用(连续)更新的滑块值
%// 3)重新绘制绘图并重新设置轴设置
函数sliderCallback(〜,〜)
delete(p);
p = plot(x,y(get(h,'value')));
轴紧
轴([0 2 * pi -10 10])
end
end
PS - 你找不到它不奇怪,没有记录。我从 Yair Altman网站了解到这一点。
I am kinda stuck here. I have tried to read and implement some simple continuous slider scripts, (like this one), but I am not getting anywhere.
What I simply want to go, is use the continuous slider value in my plot, as I slide the slider. However, I cannot figure out how to extract the value of the slider to do so.
So for example, make a continuous slider, and then use it to change the amplitude of a vector lets say, as you continuously slide it. How can that be done?
Thanks.
Something like this?
function sliderDemo
f = figure(1);
%// Some simple to plot function (with tuneable parameter)
x = 0:0.1:2*pi;
y = @(A) A*sin(x);
%// Make initial plot
A = 1;
p = plot(x, y(A));
axis tight
axis([0 2*pi -10 10])
%// re-position the axes to make room for the slider
set(gca, 'position', [0.1 0.25 0.85 0.7]);
%// initialize the slider
h = uicontrol(...
'parent' , f,...
'units' , 'normalized',... %// so yo don't have to f*ck with pixels
'style' , 'slider',...
'position', [0.05 0.05 0.9 0.05],...
'min' , 1,... %// Make the A between 1...
'max' , 10,... %// and 10, with initial value
'value' , A,... %// as set above.
'callback', @sliderCallback); %// This is called when using the arrows
%// and/or when clicking the slider bar
%// THE MAGIC INGREDIENT
%// ===========================
hLstn = handle.listener(h,'ActionEvent',@sliderCallback); %#ok<NASGU>
%// (variable appears unused, but not assigning it to anything means that
%// the listener is stored in the 'ans' variable. If "ans" is overwritten,
%// the listener goes out of scope and is thus destroyed, and thus, it no
%// longer works.
%// ===========================
%// The slider's callback:
%// 1) clears the old plot
%// 2) computes new values using the (continuously) updated slider values
%// 3) re-draw the plot and re-set the axes settings
function sliderCallback(~,~)
delete(p);
p = plot(x, y(get(h,'value')));
axis tight
axis([0 2*pi -10 10])
end
end
PS - it's not strange that you couldn't find it -- it's not documented. I know this from Yair Altman's site.
这篇关于在MATLAB中使用连续滑块的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!