Connecting the point selectively

  • Thread starter Thread starter hokhani
  • Start date Start date
  • Tags Tags
    Point
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 1K views
hokhani
Messages
610
Reaction score
22
Running the Matlab code below two discrete regions appear; one in left and the other in right.
Code:
x=20:5:800;
xpr=x*pi/180;
y=sin(xpr);
n=find(y<.2);
plot(x(n),y(n),'*')
I would like to connect the points of each region together and not to connect the rightmost point of the left region to the leftmost point of the right region so that the two regions remain separated. What should I do? I appreciate any help.
 
Physics news on Phys.org
Code:
x=20:5:800;
xpr=x*pi/180;
y=sin(xpr);
n=find(y<.2);

X = xpr(n);
Y = y(n);
N = length(X)/2;
plot(X(1:N), Y(1:N), '-*', X(N+1:end), Y(N+1:end), '-*')

Since you scaled x to xpr, I plotted xpr since it is used to calculate y. But essentially all I did was break X and Y in half, then plot the first and second halves separately in the call to plot. The '-*' ensures that plot draws the point and connects with a line. The result is below. Note that since the plots are separate, they get different colors. You can get around that by specifying the same color for both, for example by saying '-*b' to make both plots blue.

sin_plots.png
 
  • Like
Likes   Reactions: hokhani