How to show nearest value of a separate function with known x and y inputs

3 ビュー (過去 30 日間)
jacob Dyer
jacob Dyer 2019 年 10 月 9 日
回答済み: Star Strider 2019 年 10 月 10 日
I'm developing a code for psychrometric graph and I'm looking for a way to find the nearest value of a function for a given x and y input. The graph works fine, but I'm beginning to develope user state points and processes for different conditions.
For the graph, 10 intervals for RH were created from 0-100% (I plan to make 1000 intervals, but lets keep it simple for the given question) . I nested another for loop for Tdb (x-axis) for the temperature range under consideration. From there, I solved for humidity ratio, w (y-axis), as a function of RH and Tdb. I would then plot Tdb vs. w for every interval of RH, yielding the "relative humidity" curves with respect to Tdb and w. (i.e. if RH=10, a line would plot for x vs y where RH=10. it did this from 0:0.1:100, only plotting multiples of 10.
I tried to solve the equation for RH from w, but it creates unnecessary complexities and errors that I cannot reconcile. Thus, I would prefer to be able to determine the nearest of the 10 RH intervals to my state point (Tdb,w). Can you find the nearest line to a point like that? Any help would be appreciated.

回答 (1 件)

Star Strider
Star Strider 2019 年 10 月 10 日
It seems to me that you are attempting to invert your data, that is calculating an ‘x’ value from a ‘y’ value. The easiest way to do that is likely the interp1 function. Note that you can select 'nearest', 'previous', and 'next' for the interpolation method.

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by