how can I correct errors by interpolation?
이전 댓글 표시
Let's say I have this : a=[2 1 720 2.3 2.6 -40 -2 7 3] and I want to keep all the values in the interval (0,4) as they are and interpolate others either by mean (for one 'error') or by some sort of linspace. Thus, the matrix will become a=[2 1 1.65 2.3 2.6 2.7 2.8 2.9 3]. Thanks
채택된 답변
추가 답변 (1개)
dpb
2014년 4월 8일
>> a=[2 1 720 2.3 2.6 -40 -2 7 3];
>> ix=find(~iswithin(a,0,4))
>> i1=iswithin(a,0,4);
>> interp1(find(i1),a(i1),ix)
ans =
1.6500 2.7000 2.8000 2.9000
>> b=a;b(ix)=ans
b =
2.0000 1.0000 1.6500 2.3000 2.6000 2.7000 2.8000 2.9000 3.0000
iswithin is my utility helper function--
function flg=iswithin(x,lo,hi)
% returns T for values within range of input
% SYNTAX:
% [log] = iswithin(x,lo,hi)
% returns T for x between lo and hi values, inclusive
flg= (x>=lo) & (x<=hi);
that is simply "syntactic sugar" to put the ugly condition test out of sight.
You can obviously shorten the final by getting rid of some temporaries; just demonstrating the idea.
Unfortunate that you can't tell interp1 to ignore the values at the Xq locations even if present and have to make the selection w/o them to not just return the values in the a vector for them...that would save a step.
카테고리
도움말 센터 및 File Exchange에서 MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!