如何在 Scilab 应用程序中更改参数值后刷新图形?

How to refresh graph after change of parameter value in Scilab application?

我尝试制作一个简单的应用程序来求解给定起始值的 ode y_0

例如我们可以有:

dy/dt = -2ty

使用一些教程(scilab 站点和 youtube 教程)我得到了当前版本:

function dy = f(t,y)
    dy = -2*t*y;
endfunction

function updatePlot()
clf(right)
y0 = get(y0CONTROL,"value");
t0 = 0;
t = 0:0.1:10
solution = ode(y0,t0,t,f);
plot(solution, right)

endfunction

gui = figure();
gui.visible = "on";
gui.immediate_drawing = "on";

left = uicontrol(gui,...
'style','frame',...
'layout','gridbag',...
'constraints', createConstraints('border', 'left',))

right = uicontrol(gui,...
'style','frame',...
'layout','border',...
'constraints', createConstraints('border', 'center'))

y0CONTROL = uicontrol(left, ...
'style','slider', ...
'max', 10, ...
'min', -10, ...
'value',-1,...
'callback', 'updatePlot')

updatePlot()

正如你所看到的,我试图使用 clf(right) 来清除之前的图表,并使用 plot(solution,right) 在现在可能是空的 right 框架中绘制。

但此尝试失败了 - 滑块移动后旧线条仍保留在图表上。

请告诉我如何更正此问题。

原来可以通过代入来达到清爽的效果 clf(right)

current_axes = gca()
delete(current_axes)

This 很有用。

更流畅的解决方法就是改变曲线数据:

   function updatePlot()
     y0CONTROL;
     y0 = y0CONTROL.value
     curve=y0CONTROL.user_data
     t0 = 0;
     t = 0:0.1:10
     solution = ode(y0,t0,t,f);
     if curve==[] then //first call
       plot(t,solution)
       curve=gce().children(1); //the handle on the curve
       y0CONTROL.user_data=curve;
     else //other calls
       ax=gca();
       ax.data_bounds(:,2)=[min(solution);max(solution)];
       curve.data(:,2)=solution.';
     end
   endfunction

   gui = figure();
   ax=gca();
   gui.visible = "on";
   gui.immediate_drawing = "on";
   y0CONTROL = uicontrol(gui, ...
   'style','slider', ...
   'position',[20 20 100 20],...                      
   'max', 10, ...
   'min', -10, ...
   'value',-1,...
   'callback', 'updatePlot()',...
   'user_data',[])
   ax.background=-2;

   updatePlot()