在 MATLAB 中使用连续滑块的值 [英] Use the value of continuous slider in MATLAB

查看:35
本文介绍了在 MATLAB 中使用连续滑块的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有点卡在这里.我试图阅读和实现一些简单的连续滑块脚本,(喜欢这个),但我没有得到任何结果.

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?

谢谢.

推荐答案

像这样?

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 - 找不到它并不奇怪 - 它没有记录在案.我从 Yair Altman 的网站 知道这一点.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆