フィルターのクリア

intersction graph with line

1 回表示 (過去 30 日間)
Imo
Imo 2012 年 8 月 30 日
Hi everyone, can u help me out im still pretty green. This is a simple one but I cant figure it out. I tried to look for similar problem but did not find satisfy answer.
I'm having some data set which I plot with basic plot command. My question is, can matlab give me right away answer for the y value at my distance of say 4.5 like in the simplify example having in mind that my graph is just a line connecting y values
x=1:10;
y=-5*rand(1,10);
plot(x,y)
hold on
plot([4.5 4.5],[0 -5],'r')
thanks in advance.

採用された回答

Star Strider
Star Strider 2012 年 8 月 30 日
編集済み: Star Strider 2012 年 8 月 30 日
I am not exactly certain what you want, but my guess would be:
p = polyfit(x,y,1);
y1 = polyval(p, 4.5);
The value returned for y1 would then be the value that might be expected to be at an x value of 4.5 on that particular iteration based on a linear fit. Since your data are changing between iterations (they are random), y1 will change with them.
If you want to know what the value is on a line between connecting points, to calculate the value for 4.5, the easiest way is probably:
p = polyfit([4 5], y([4 5]), 1);
y1 = polyval(p, 4.5);
That is how I would do it.
(And thank you Walter for your editing.)
  2 件のコメント
Imo
Imo 2012 年 8 月 31 日
編集済み: Imo 2012 年 8 月 31 日
I'm sorry if I confused you. Your solution is what I need, thank you very much. Rand function is just to give me any set of data just for quick example here. I actually have points that represent my river profile and I need matlab to give me depths in particular places of that profile based on that interpolation.
Only problem would be here that my profile consist of a large amount of dots and i don't know the values of y bewven my specified point (in example 4.5) that i need for interpolation. I thought matlab will figure it out on its own:)
Star Strider
Star Strider 2012 年 8 月 31 日
It is my pleasure to help!
I do not know what your data look like so I cannot suggest a specific solution that might work for you in all situations. However, I suggest you also look at MATLAB's various interpolation functions, for example interp1, and more generally, the functions in Interpolation and Computational Geometry.
Thank you for accepting my answer.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDirected Graphs についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by