【发布时间】:2014-11-07 08:11:47
【问题描述】:
我编写了以下代码来绘制水箱中水的高度与时间的关系。
A_t = 16;
[h1, t1] = update_plot(A_t);
f = figure;
h = plot(t1, h1);
b = uicontrol('Parent',f,'Style','slider','Position',[81,54,419,23], 'value',A_t, 'min',14, 'max',17);
bgcolor = f.Color;
set(b,'Callback',@(es,ed) updateSystem(h,update_plot((es.Value))))
更新h(水的高度)和t(时间)向量的函数是:
function [h1, t1] = update_plot(A_t)
t = 0:0.01:100;
h = zeros(1, length(t));
h_init = 20;
t_0 = 0;
myeps = 1e-5;
i = 1;
h(1) = h_init;
while h(i) > myeps
i = i + 1;
h(i) = (sqrt(h_init) - (0.18/A_t)*sqrt(981/2)*(t(i) - t_0))^2;
h1 = h(1:i);
t1 = t(1:i);
end
参数A_t 是我想使用滑块的变量。
我无法让回调函数工作。
我希望在移动滑块时更新绘图。
【问题讨论】:
-
欢迎来到 StackOverflow。第一个问题写得很好(+1)。你唯一能记住的就是这样写变量名。您可以使用 `-sign 作为环境来获取“代码模式”。对于您的问题:您是否检查过您的函数对于不同的 A_t 值是否正确?
标签: matlab graphics callback matlab-figure matlab-guide