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
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.
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.
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])
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)
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'})
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!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 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)
