Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Connecting the point selectively

  1. Apr 24, 2015 #1
    Running the Matlab code below two discrete regions appear; one in left and the other in right.
    Code (Text):

    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.
     
  2. jcsd
  3. Apr 24, 2015 #2

    kreil

    User Avatar
    Gold Member

    Code (Text):

    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
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Connecting the point selectively
Loading...