How to find two points with same x coordinate when two graphs are plotted in a same plot?

조회 수: 3 (최근 30일)
Hello everyone. I need a help from you all. I am trying to plot two different graphs (say G1 and G2) in a same plot using hold on command. Now, I have marked a point on G1 say P1(x,y). I want to find the point P2(x,y) on the other graph G2 for same x coordinate. What commands I can use to achieve this? I hope my question is clear to you and can anyone please help me? Thanks in advance.

답변 (1개)

Meade
Meade 2016년 4월 20일
Give this a shot:
n = 1% The number of identical 'x' coordinates you want to find, delete "n" to find them all
idx = find(G2(:,1) == P1(1,1),n); % Finds the idx of the points in G2 matching P1(x)
P2 = G2(idx,:) % Assigns all matching points in G2 to P2;
or more concisely:
P2 = G2(G2(:,1) == P1(1,1),:)

카테고리

Help CenterFile Exchange에서 2-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