-3

I encounter this message, " Subscript indices must either be real positive integers or logicals." Error in ==> plot(b(s,1),b(s,2),'r*'). this is my code

ptsIntersect=floor(ptsIntersect);
    for s1=1:numBorderPoints
       d1=sqrt((b(s1,1)-ptsIntersect(1,1)).^2 + (b(s1,2)-ptsIntersect(1,2)).^2);
       if (d1<2)
           break;
       end
    end
    plot(b(s1,1),b(s1,2),'*')
     % find second point  of border in intersection
    for s2=1:numBorderPoints
       d2=sqrt((b(s2,1)-ptsIntersect(2,1)).^2 + (b(s2,2)-ptsIntersect(2,2)).^2);
       if (d2<2)
           break;
       end

    end

    plot(b(s2,1),b(s2,2),'*')

    if ( s2-s1>5)
          s=(s1+s2)/2;
          hold on
          plot(b(s,1),b(s,2),'r*')
    end

1 Answers1

2

Just before the error, both s1 and s2 are positive integers. But when you do s=(s1+s2)/2, it might happen that s is not an integer, e.g. (3+2)/2=2.5.

Type s in the command window and its value will be displayed.

marsei
  • 7,691
  • 3
  • 32
  • 41