【问题标题】:calculating time averaged data in matlab在matlab中计算时间平均数据
【发布时间】:2013-10-07 11:13:12
【问题描述】:

我有一个数据向量(名为 ydot)和一个时间向量,当我绘制 ydot 与时间的关系图时,我得到一个像正弦函数一样的周期性图形,我如何计算时间平均 ydot?

以下代码计算 ydot 和时间的精确值:

T=(2*pi)/(160e6)
tspan=linspace(0,2*T,1500)
current=linspace(0,1e-6,40);
for k=1:length(current)
f = @(y, t) (current(k)/3.2911e-016)-(2.6151e+009)*sin(y)+(4.8448e+008)*sin(y+0.5697)+(5.2266e+008)*sin((160e6)*t)*cos(y);
[t{k}, y{k}] = ode45(f,tspan,2e22);
end
y1=cell2mat(y);
t1=cell2mat(t);
for k=1:length(tspan)
for j=1:length(current)
ydot(k,j)=(current(j)/3.2911e-016)-(2.6151e+009)*sin(y1(k,j))+(4.8448e+008)*sin(y1(k,j)+0.5697)+(5.2266e+008)*sin((160e6)*t1(k,j))*cos(y1(k,j));
end
end

这给出了 40 种不同电流的 ydot,以下代码将绘制特定电流 (k) 的 ydot/时间(其中 k=1:40):

plot(t1(:,k),ydot(:,k))

【问题讨论】:

标签: matlab average trigonometry


【解决方案1】:

如果你的意思是一个假设的时间平均值,你可以简单地通过取 ydot 的平均值来得到这个

x = 0:0.1:10; % define time
ydot = sin(x); % get some data for ydot
average = mean(ydot); % use mean function to get time average
plot(x, ydot, x, average); % plot both, average (which should be approximately zero for this sine and ydot vs x

如果没有,您需要更清楚地指定您的任务。

【讨论】:

  • 我需要在一个周期内取平均值,我不知道周期的确切值。
【解决方案2】:

如果时间值是等距的,lhcgeneva 的解决方案就可以了。 如果没有,您只需写下适当的积分,例如通过陷阱:

time_averaged_mean = trapz(time, ydot) ./ (time(end) - time(1));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-29
    • 1970-01-01
    • 1970-01-01
    • 2011-03-28
    • 1970-01-01
    相关资源
    最近更新 更多