필터 지우기
필터 지우기

How to find inf and sup of a datum not contained in an array ?

조회 수: 2 (최근 30일)
Virgilio Grigiotti
Virgilio Grigiotti 2021년 7월 6일
댓글: Virgilio Grigiotti 2021년 7월 8일
Hello all, I have a column vector containing elevations of cross section (x-data are the stations). I have to modify this elevation and I have for example y = 32 mt as output.
In the array I have some elevations that are different from this one and I want to know how to find the index of the first value before and the first value after y = 32 mt (y_new) (with the minimum distance along x from minimum elevation) that are contained in the array and so interpolate the relative new x. 32mt is clearly not contained in the array.
Thanks for reading.
  댓글 수: 2
dpb
dpb 2021년 7월 6일
편집: dpb 2021년 7월 6일
Ya' lost me, sorry...
Give us an example and attach a sample dataset that illustrates what you're after.
Sounds as though interp1 would likely do the trick, but need details to confirm just what it is you're after.
ADDENDUM
interp1 requires the independent variable be unique and not multi-valued which may not cut it if the data are from a FE model coordinates or the like, though.
Jan
Jan 2021년 7월 6일
Some example data would be useful. Is the vector sorted or does it contain unique values? This is more important than the meaning of the values: "elevations of cross section".

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

답변 (1개)

Jan
Jan 2021년 7월 6일
x = randi([1, 100], 1, 30);
y = 1 + rand * 99;
[~, index] = min(abs(x - y));
indexBefore = max(1, index - 1);
indexAfter = indexBefore + 1;
  댓글 수: 5
dpb
dpb 2021년 7월 7일
This may require iterative solution to test alternatives with the doubly-valued y elevations as you have, depending upon the new y value and just where it is intended for it to go.
It may, in fact, be intractable in general without visual inspection given the shape of the sample curve and the data.
But, for the specific case since it is the last one wanted and the first place that y actually crosses the threshold,
>> ix=find(y<y_new,1);
>> y(ix-1:ix)
ans =
37.6000 37.3000
>>
gets the point desired for the particular case. In general is going to be tough methinks...
Here's the given data blown up some to see the detail in the area of interest --
Virgilio Grigiotti
Virgilio Grigiotti 2021년 7월 8일
it's not valid for all the situations in fact, but thank you for help :)

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

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by