Scilab - gui - axes auto_clean 调整滑块时的图形...?

Scilab - gui - axes auto_clean the graph during adjusting the slider ...?

我正在尝试在 scilab 中创建一个简单的 GUI,仅用于显示函数 a'sin(x) 的图形,其中滑块驱动 "a" 的值。我似乎没有找到一种方法来仅显示与 "a" 当前值对应的曲线...它只是向现有曲线添加新曲线。我希望有一个简单的解决方案,因为我目前无法进一步了解(我只有一些 Mathematica 经验)。我使用的非常简单的代码是:

// This GUI file is generated by guibuilder version 3.0
//////////
f=figure('figure_position',[400,50],'figure_size',
[656,581],'auto_resize','on','background',[33],'figure_name','Graphic 
window number %d');
//////////
delmenu(f.figure_id,gettext('File'))
delmenu(f.figure_id,gettext('?'))
delmenu(f.figure_id,gettext('Tools'))
toolbar(f.figure_id,'off')
handles.dummy = 0;
handles.slider=uicontrol(f,'unit','normalized','BackgroundColor',
[-1,-1,-1],'Enable','on','FontAngle','normal','FontName','Tahoma',
'FontSize',[12],'FontUnits','points','FontWeight','normal',
'ForegroundColor',[-1,-1,-1],'HorizontalAlignment','left','ListboxTop',
[],'Max',[1],'Min',[0],'Position',[0.0359375,0.78125,0.2625,0.09375],
'Relief','default','SliderStep',
[0.01,0.1],'String','slider1','Style','slider','Value',
[0],'VerticalAlignment','middle','Visible','on','Tag','slider',
'Callback','slider_callback(handles)')
handles.graph= newaxes();handles.graph.margins = [ 0 0 0 
0];handles.graph.axes_bounds = [0.31875,0.01875,0.6640625,0.925];

//////////
// Callbacks are defined as below. Please do not delete the comments as 
it will be used in coming version
//////////

function slider_callback(handles)
//Write your callback for  slider  here
x=0:0.1:10;
a=handles.slider.Value;
plot(x,a*sin(x));
endfunction

预先感谢您的帮助。

默认情况下每个图形指令将其结果添加到当前显示 如果要在显示新的图形指令之前自动清除图形,可以将轴的自动清除 属性 设置为 "on"。另一种解决方案是使用删除功能删除以前的绘图。

如果不希望显示刻度可以使用 xpoly 函数而不是 plot 函数

// This GUI file is generated by guibuilder version 3.0
//////////
f=figure('figure_position',[400,50],'figure_size',...
[656,581],'auto_resize','on','background',[33],'figure_name','Graphic window number %d');
//////////
delmenu(f.figure_id,gettext('File'))
delmenu(f.figure_id,gettext('?'))
delmenu(f.figure_id,gettext('Tools'))
toolbar(f.figure_id,'off')
handles.dummy = 0;
handles.slider=uicontrol(f,'unit','normalized','BackgroundColor',...
[-1,-1,-1],'Enable','on','FontAngle','normal','FontName','Tahoma',...
'FontSize',[12],'FontUnits','points','FontWeight','normal',...
'ForegroundColor',[-1,-1,-1],'HorizontalAlignment','left','ListboxTop',...
[],'Max',[1],'Min',[0],'Position',[0.0359375,0.78125,0.2625,0.09375],...
'Relief','default','SliderStep',...
[0.01,0.1],'String','slider1','Style','slider','Value',...
[0],'VerticalAlignment','middle','Visible','on','Tag','slider',...
'Callback','slider_callback(handles)')
handles.graph= newaxes();
handles.graph.margins = [ 0 0 0 0];
handles.graph.axes_bounds = [0.31875,0.01875,0.6640625,0.925];
handles.graph.data_bounds=[0 -1.2;10 1.2];
handles.graph.auto_clear="on";
//////////
// Callbacks are defined as below. Please do not delete the comments as 
//it will be used in coming version
//////////

function slider_callback(handles)
//Write your callback for  slider  here
x=0:0.1:10;
a=handles.slider.Value;
drawlater()
//delete(handles.graph.children)
xpoly(x,a*sin(x))
handles.graph.data_bounds=[0 -1.2;10 1.2];
drawnow
//plot(x,a*sin(x));
endfunction

您可以访问图形的折线并直接更改数据 (x,y)。 在某处放置一个空(或虚拟)图(例如靠近 uicontrols 的定义)。

然后在回调函数中获取当前axes对象:

axes1=gca();// get the current axes

假设你只绘制了一条线,那么你的折线由 axes1.children.children 寻址(如果你绘制多条线,它们由 axes1.children.children(1), axes1.children.children(2 ) 等等)。

x 和 y 数据位于折线的 "data" 中,因此您只需更新此数据:

axes1.children.children.data=xymatrix([x1,y1;x2,y2;x3,y3;...xn,yn]);

您的回调函数可能如下所示:

function slider_callback(handles)
//Write your callback for  slider  here
x=zeros(101,2);//define matrix with 101 rows and 2 columns
x(:,1)=0:0.1:10;//fill first column with x axis values
a=handles.slider.Value;//get slider value
x(:,2)=a*sin(x(:,1));//fill second column with y axis values
axes1=gca();//get current axes
axes1.children.children.data=x;//update polyline data with new xy data
endfunction