How do I find the instersection on my plot?
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
I have a plot with the errorbar. The data coming from a matrix 21x6 and the errorbar from another matrix. I need to find where (for a given y-axis value) the functions intersect the curves and at what coordinate. Since the values of the graph are given by a matrix, only the y axis correspond to the physical values, for the x axis I changed the values via
xticks([1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21])
xticklabels({'-20','-18','-16', '-14', '-12', '-10', '-8', '-6','-4','-2','0','2', '4', '6', '8', '10', '12', '14', '16', '18', '20'})
The graph is this one:

採用された回答
You can use fzero, e.g.,
fun=@(x)x^2;
y=4;
x_intersect=fzero(@(x) fun(x)-y,[0,1e6])
x_intersect = 2.0000
12 件のコメント
If you only have discrete samples of the curves, you will have to select an interpolation model, e.g.
xdata=(0:0.3:10); ydata=xdata.^2; %plotted samples
fun=griddedInterpolant(xdata,ydata,'linear'); %interpolator
y=4; %given y value
x_intersect=fzero(@(x) fun(x)-y,[0,1e6])
x_intersect = 1.9949
HelpAStudent
2021 年 10 月 11 日
I don't understand
xdata=(0:0.3:10);
ydata=xdata.^2;
Can you explain?
Matt J
2021 年 10 月 11 日
It's just example plot data.
HelpAStudent
2021 年 10 月 11 日
Ok, I think you does not understand my problem. My plot is a matrix. I have 6 curves on the plot because the matrix it's 21x6. A curve was drawn from the 21 values identified. For a total of 6 curves with 21 values each (the dots in the graph). If you see the graph I know a value of the yaxis but it does not correspond on something because the plot is made of the matrix
Matt J
2021 年 10 月 11 日
You Accept-clicked the answer so I assume you figured it out? If not, I don't see how my answer is invalid. If you have 6 curves, just apply my technique 6 times, or use a loop.
HelpAStudent
2021 年 10 月 11 日
Your answer it's not ok, because you don't use the right function: you used fun=@(x)x^2; but I have a matrix, so I don't know the equation for my function. I just wanna know HOW from the graph that I share with you I can find where for y=80 the courves interpolate. The courves are the columns of the matrix and the rows are the point (the dots on the plot)
I already showed you how to modify the technique when you only have discrete plot data xdata and ydata. Here it is again.
xdata=(0:0.3:10); ydata=xdata.^2; %plotted samples
fun=griddedInterpolant(xdata,ydata,'linear'); %interpolator
y=4; %given y value
x_intersect=fzero(@(x) fun(x)-y,[0,1e6])
HelpAStudent
2021 年 10 月 11 日
Yes, but the y data are not the power of the x data as you write. And I can't give an y value because I have just the matrix of the value. I did not create a plot from x and y values, I create a plot from the value and matlab create somehow the value of the x axis and y axis, but I have them only on the graph, not as a variable in my script
The ydata would be a particular column in your matrix, which you do have. The xdata, based on what you posted, would just be,
xdata=-20:2:20
xdata = 1×21
-20 -18 -16 -14 -12 -10 -8 -6 -4 -2 0 2 4 6 8 10 12 14 16 18 20
In other words, you could have (and probably should have) plotted the data as follows, rather than manipulating the xticklabels.
plot(xdata,Matrix)
HelpAStudent
2021 年 10 月 11 日
I do not have ydata as the columns of my matrix. As you can see:
meanbasketT = transpose(meanbasket);
y = meanbasketT;
e = transpose(devstdbasket);
figure; errorbar(y,e,'-o')
legend({'Function 1', 'Function 2', 'Function 3', 'Function 4', 'Function 5', 'Function 6'}, 'Location', 'northwest', 'FontSize',14 );
xticks([1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21])
xticklabels({'-20','-18','-16', '-14', '-12', '-10', '-8', '-6','-4','-2','0','2', '4', '6', '8', '10', '12', '14', '16', '18', '20'})
HelpAStudent
2021 年 10 月 11 日
The meanbasketT is 21x6 that's why I have 6 function and 21 dots for function
The ydata is not a particular column. The column as I told you before are the different line
Yes, the ydata in my original example also represented one particular line, but as I told you you can loop over your matrix columns and apply my technique to each.
xdata=-20:2:20
for i=1:6
ydata=Matrix(:,i);
y=...
fun=griddedInterpolant(xdata,ydata,'linear'); %interpolator
x_intersect(i) = fzero(@(x) fun(x)-y,[0,1e6])
end
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Line Plots についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
