How to find inf and sup of a datum not contained in an array ?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
dpb
el 6 de Jul. de 2021
Editada: dpb
el 6 de Jul. de 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
el 6 de Jul. de 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".
Respuestas (1)
Jan
el 6 de Jul. de 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 comentarios
dpb
el 7 de Jul. de 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 --
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/677168/image.jpeg)
Ver también
Categorías
Más información sobre Matrices and Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!