フィルターのクリア

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

3 ビュー (過去 30 日間)
Virgilio Grigiotti
Virgilio Grigiotti 2021 年 7 月 6 日
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 Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by