Find X for a given Y using interpolation
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
Hi all,
Suppose
x = [5 8 9 11 12.5 17];
y = [2 3.5 4.0 5.3 6.7 8.2];
Now I want to find the corresponding value for x where y = 4.8 using interpolation. I was wondering if there is any function in MATLAB which can do this calculation.
채택된 답변
Dyuman Joshi
2023년 9월 22일
x and y are not mapped one-to-one for interpolation, there is an element missing in y.
interp1 is what you are looking for.
댓글 수: 8
Roohollah
2023년 9월 22일
Thanks for reminding me for the issue.
What I need is a function to input x,y and y = 4.8. Then it returns the corresponding x for y = 4.8.
Roohollah
2023년 9월 22일
Many thanks.
interp1 worked well.
Dyuman Joshi
2023년 9월 22일
편집: Dyuman Joshi
2023년 9월 22일
Look into the documentation (the link I attached above) for more info.
x = [5 8 9 11 12.5 17];
y = [2 3.5 4.0 5.3 6.7 8.2];
x0 = interp1(y,x,4.8)
x0 = 10.2308
Roohollah
2023년 9월 22일
Seems to be wrong. x0 must be between 11 and 12.5.
As y0 is between 4 and 5.3, so correspondingly, x0 should be between 9 and 11, which it is.
Yes, you are right.
As the last question. I am working on my real data. This is the code I use;
delta40 = interp1(F,delta,F40);
And I get the following error message:
Error using matlab.internal.math.interp1
Sample points must be unique.
Error in interp1 (line 188)
VqLite = matlab.internal.math.interp1(X,V,method,method,Xqcol);
Error in Test (line 40)
F40 = 0.4 * Fmax; delta40 = interp1(F,delta,F40);
What does "Sample points must be unique." mean?
"What does "Sample points must be unique." mean?"
Let's introduce a repeating value in the data set -
y = [2 2 3.5 4.0 5.3 6.7 8.2 ];
x = [5 6.5 8 9 11 12.5 17 ];
Now if you want to interpolate for y between 2 and 3.5, say 3, which x values should be used for interpolation?
5-8 or 6.5-8? Interpolation for such a case does not make sense.
So, we have to use non-repeating values - a.k.a unique values in MATLAB terminology. That's what the error is stating.
Now, as 6.5-8 is a subset of the range 5-8 for the same value of 2, we can eliminate it from our data and then interpolate -
%Get unique values of the array in sorted manner
[y,idx] = unique(y)
y = 1×6
2.0000 3.5000 4.0000 5.3000 6.7000 8.2000
idx = 6×1
1
3
4
5
6
7
x = x(idx)
x = 1×6
5.0000 8.0000 9.0000 11.0000 12.5000 17.0000
interp1(y,x,3)
ans = 7
Note that this is just one of the possible cases of data with repeating values.
Roohollah
2023년 9월 22일
Many thanks
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Interpolation에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
