简体   繁体   English

从两个向量创建 function 句柄以传递给 MATLAB 中的积分 function

[英]Creating function handle from two vectors to pass to an integral function in MATLAB

I'm not sure if I'm being thick here, but I'm not used to function handles etc.我不确定我是否在这里很厚,但我不习惯 function 手柄等。

I am trying to find the integral of some raw accelerometer data i have, and was advised by a friend that using Simpsons might be the best way.我试图找到我拥有的一些原始加速度计数据的积分,一位朋友建议我使用辛普森一家可能是最好的方法。 So i found that MATLAB has the "quad()" function but it accepts a function handle as a parameter.所以我发现 MATLAB 具有“quad()” function 但它接受 function 句柄作为参数。

If i have two vectors, one for time, one for acceleration, how can i create them into a function handle to send to quad()?如果我有两个向量,一个用于时间,一个用于加速,我如何将它们创建为 function 句柄以发送到 quad()?

Thanks谢谢

Use one of these two使用这两个之一

f = @(x) sin(x);
x = linspace(a,b,200);
y = f(x);               % values at f(x)

s1 = trapz(x,y);        % you can use trapz
s2 = integral(f,a,b);   % you can use integral

Compare the results.比较结果。 Experiment实验

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM