3

Matlabでの補間についてお聞きしたいです。同じ行で 2 つの異なる補間を行うことが可能かどうかを知りたいです。たとえば、最初は線形補間を行い、途中でほぼスプラインのような別の種類の補間を行います。

主な問題は、線形補間を行ったことです。最初は完璧ですが、ある時点で、別のタイプの方が良いと思います。これが可能な場合、変更したい場所をどのようにコーディングできますか? Matlab に関するドキュメントを確認しようとしましたが、補間の変更については何も見つかりませんでした。

よろしくお願いします。

4

1 に答える 1

3

あなたの投稿に対して私が行ったコメントについて詳しく説明させてください。

分割で 2 つの異なる関数を使用して入力配列から出力配列を作成する場合は、次のコード例のように配列インデックス範囲を使用できます。

x = randn(20,1); %//your input data - 20 random numbers for demonstration
threshold = 5; %//index where you want the change of algorithm
y = zeros(size(x)); %//output array of zeros the same size as input

y(1:threshold)     = fun1(x(1:threshold));
y(1+threshold:end) = fun2(x(1+threshold:end));

必要に応じて の事前割り当てをスキップしてy、追加データを出力の最後に連結することができます。これは、関数が入力要素の数に対して異なる数の出力要素を返す場合に特に役立ちます。この構文を以下に示します。

y = fun1(x(1:threshold));
y = [y; fun2(x(1+threshold:end))];

編集:

以下のあなたの投稿に応えて、ここに完全な例があります. . .

clc; close all

x = -5:5; %//your x-range
y = [1 1 0 -1 -1 0 1 1 1 1 1]; %//the function to interpolate
t = -5:.01:5; %//sampling interval for output

xIdx = 5; %//the index on the x-axis where you want the split to occur
tIdx = floor(numel(t)/numel(x)*xIdx);%//need to calculate as it is at a different sample rate

out = pchip(x(1:xIdx),y(1:xIdx),t(1:tIdx));
out = [out spline(x((1+xIdx):end),y((1+xIdx):end),t((1+tIdx):end))];

%//PLOTTING
plot(x,y,'o',t,out,'-',[x(xIdx) x(xIdx)], [-1.5 1.5], '-')
legend('data','output','split',4);
ylim ([-1.5 1.5])

与えるでしょう。. .

ここに画像の説明を入力

于 2012-09-12T11:52:52.740 に答える