我有一個數據向量(名爲ydot)和時間向量,當我繪製ydot與時間的關係曲線時,我得到一個像正弦函數那樣的週期性圖形,我如何計算時間平均ydot ?在matlab中計算時間平均數據
以下代碼計算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
這給出ydot 40個不同的電流,下面的代碼將繪製ydot /時間爲特定的電流(K)(其中,k = 1 :40):
plot(t1(:,k),ydot(:,k))
假設你需要某種移動平均線:http://www.mathworks.co.uk/help/matlab/data_analysis/filtering-data.html – nkjt