Do an interpolation in matlab

Hi,
I'm newbie in Matlab and I'm trying to do an interpolation but it doesn't work ("The values of X should be distinct.") I don't know exactly what's wrong.
load doc_1.txt
x= doc_1(:,2);
y= doc_2(:,3);
z= 399.25:1:2179.5;
yi= interp1(x,y,z);
plot(x,y,'o',z,yi)
Thanks in advance,

댓글 수: 4

Oleg Komarov
Oleg Komarov 2012년 7월 30일
I assume "The values of X should be distinct" is an error. As it says, your x values should all be different.
klipya
klipya 2012년 7월 30일
편집: Andrei Bobrov 2012년 7월 30일
Thanks Oleg, I will apply some function to erase them or I will erase it directly. One other question. I have different values like:
X Y
352.4 0.5050
352.5 2.4874
Is there any possibility to get only one value for 352, for example? Thanks a lot!
interp1(X,Y,352,'linear','extrap')
klipya
klipya 2012년 8월 6일
Thanks Andrei. Interpolation works well, thank you. It's not that what I want. I have a lot of values like 352.4, 352.5 354.3... and I want to get, with the interpolation, only one value from every number. Is that possible?
For example, for the value 352 I want to get one number.

댓글을 달려면 로그인하십시오.

답변 (2개)

Titus Edelhofer
Titus Edelhofer 2012년 8월 6일

0 개 추천

Hi,
you will need to average all values between 352 and 353. To this end use histc to find those effiently and then loop. Here ist the code (only for interval [352 - 353]), the more general should then be not too difficult:
x = [351 351.5 352.2 352.3 353.5 354.5];
y = rand(size(x));
edges = 350:355;
[n,bin] = histc(x, edges);
% for the 352 average on all values between 352 and 354
x352 = x(bin==3)
% x352 is just for illustration, what you need is y352:
y352 = mean(y(bin==3))
Titus
Andrei Bobrov
Andrei Bobrov 2012년 8월 6일
편집: Andrei Bobrov 2012년 8월 6일

0 개 추천

variant
X = [352.4, 352.5 354.3;0.5050,2.4874,1]';
[xa,~,c]=unique(fix(X(:,1)));
Xout = [xa,accumarray(c,X(:,2),[],@mean)];

카테고리

도움말 센터File Exchange에서 Interpolation에 대해 자세히 알아보기

질문:

2012년 7월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by