2013-10-07 173 views
0

我有一個數據向量(名爲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)) 
+0

假設你需要某種移動平均線:http://www.mathworks.co.uk/help/matlab/data_analysis/filtering-data.html – nkjt

回答

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 
得到這個

如果不是,則需要更清楚地指定您的任務。

+0

我需要一個週期來獲得平均,我不知道期限的確切價值。 – user2822314

+0

謝謝:)它的工作原理。 – user2822314

0

如果時間值是等距的,lhcgeneva的解決方案就沒問題。如果不是,你只需要寫下適當的積分,例如通過trapz:

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

您的解決方案有效:) – user2822314