間隔と長さの異なるベ​クトルに依存する値の​誤差を計算したい

10 次查看(过去 30 天)
Masaki Maeda
Masaki Maeda 2019-10-7
二つの二次元配列の誤差を計算したいです。
二つの配列はそれぞれ時間tに依存する値 y1(t), y2(t)
なのですが、時間は不規則な増分かつ、y1とy2はそれぞれ異なる時刻に記録されたものです。
同じ時刻でy1とy2の誤差を計算するには
どちらかの計測時刻に合わせて線形補間して、、と考えたのですがうまくいきません。
以下、モデルのコードです。よろしくお願い致します。
t1 = sort(rand(1,20)).*10; t2 = sort(rand(1,15)).*10;
y1 = sin(t1); y2 = cos(t2);
figure(1)
plot(t1,y1,'or-',t2,y2,'ob-');

回答(1 个)

Shunichi Kusano
Shunichi Kusano 2019-10-7
1次元信号の内挿でしたらinterp1で行えます。
下のサンプルはsin波を異なる時間でサンプリングしたときの例となります。
t1 = sort(rand(1,20)).*2*pi;
t2 = sort(rand(1,15)).*2*pi;
y1 = sin(t1);
y2 = sin(t2);
figure
plot(t1,y1,'or-',t2,y2,'ob-');
title('original simulated data');
legend('y1', 'y2');
y1_ = interp1(t1, y1, t2);
figure;
plot(t2, y1_, 'or-', t2, y2, 'ob-')
title('resampled result')
legend('resampled y1 at t2', 'y2')

类别

Help CenterFile Exchange 中查找有关 内挿 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!