图上的MATLAB简单滑块 [英] MATLAB simple slider on a figure

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

问题描述

我有一个矩阵,一次要绘制一列.是否可以在MATLAB图形中添加滑块(无需进行繁琐的GUI编程),以便通过移动滑块在当前轴上显示不同的列?

I have a matrix to be plotted one column at a time. Is it possible to add a slider to a MATLAB figure (without heavy GUI programming) so that by moving the slider, different columns are shown in the current axis?

推荐答案

以下是滑块绘制相应列的代码:

Here is a code for a slider to plot corresponding column:

m = ones(5,1)*(1:5);
slmin = 1;
slmax = size(m,2);
plot(m(:,1))
hsl = uicontrol('Style','slider','Min',slmin,'Max',slmax,...
                'SliderStep',[1 1]./(slmax-slmin),'Value',1,...
                'Position',[20 20 200 20]);
set(hsl,'Callback',@(hObject,eventdata) plot(m(:,round(get(hObject,'Value')))) )


编辑:

为获得更好的性能,您可以仅更新YData值:

For better performance you can just update the YData values:

set(hsl,'Callback',@(hObject,eventdata) ...
    set(hline,'YData',m(:,round(get(hObject,'Value')))) )

要固定y轴限制,只需在首次调用plot之后用ylim([0 6])手动设置它们即可.

To fix y axes limit, just set them manually with ylim([0 6]) after first plot call.

这篇关于图上的MATLAB简单滑块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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