Effacer les filtres
Effacer les filtres

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

3 vues (au cours des 30 derniers jours)
Virgilio Grigiotti
Virgilio Grigiotti le 6 Juil 2021
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 commentaires
dpb
dpb le 6 Juil 2021
Modifié(e) : dpb le 6 Juil 2021
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 le 6 Juil 2021
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".

Connectez-vous pour commenter.

Réponses (1)

Jan
Jan le 6 Juil 2021
x = randi([1, 100], 1, 30);
y = 1 + rand * 99;
[~, index] = min(abs(x - y));
indexBefore = max(1, index - 1);
indexAfter = indexBefore + 1;
  5 commentaires
dpb
dpb le 7 Juil 2021
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 le 8 Juil 2021
it's not valid for all the situations in fact, but thank you for help :)

Connectez-vous pour commenter.

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by