Find neighboring values of a target value in array

1 回表示 (過去 30 日間)
Georg Söllinger
Georg Söllinger 2016 年 9 月 12 日
コメント済み: Walter Roberson 2016 年 9 月 13 日
Hi everybody,
I have a matrix, whose values represent the points of geometry-changes of a specific 3D geometry (mainly sorts of angularly aligned cuboids) in intervals. What I want to do is: enter a height, in which the geometry is analyzed. Afterwards, the 2D geometry in the user defined height is processed.
With my knowledge, I would achieve the solution with a combination of for-loop (heigth-direction entities of the matrix) and some if-conditions, but I am sure, there exists a more elegant solution for my problem.
Is there any function, which finds the two height-value neighbors in the matrix entities? Then, the interpolation part is not a problem any more.
Can anyone help me? Thanks in advance!
Best wishes, Georg

回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 9 月 13 日
Depending on how your values are represented, slice() might be what you need.
  2 件のコメント
Georg Söllinger
Georg Söllinger 2016 年 9 月 13 日
Hello Mr. Roberson,
Thanks for your reply! Actually, this function is not really what I need. I have z-Values arranged in an array together with x and y values, e.g.:
z = [7.200;16.715;36.245]
x = [...;...;...]
y = [...;...;...]
and e.g. a desired height of 30 -> the neighboring values in the array are 16.715 & 36.245. The function should either return the values or their array index.
Walter Roberson
Walter Roberson 2016 年 9 月 13 日
interp1(z, 1:length(z), height, 'previous')

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by