"find" is not finding what I want it to?
    5 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
    Kristin Aldridge
 il 12 Nov 2021
  
    
    
    
    
    Commentato: Image Analyst
      
      
 il 12 Nov 2021
            I have a data set of 8341 numbers and I want to create two vector of the numbers between 3 and 200, and another of the numbers outside of that range. AI is the area included (between 3 and 200), and AE is the area excluded (below 3 or above 200) but when I run them they keep giving me the same amount (8341). Any idea what's going on?
I'm trying to plot the area included as a yellow ellipse, and the area excluded as a green ellipse. 
 s = regionprops(BW, 'Area','Orientation', 'MajorAxisLength', ...
                    'MinorAxisLength','Area', 'Eccentricity', 'Centroid'); 
            hold on
            phi = linspace(0,2*pi,50);
            cosphi = cos(phi);
            sinphi = sin(phi);
            areas=[s.Area]
            AI=find(3<areas<200);
            AE=find(3.0>areas<200);
            for k = AI
                            xbar = s(k).Centroid(1);
                            ybar = s(k).Centroid(2);
                            a = s(k).MajorAxisLength/2;
                            b = s(k).MinorAxisLength/2;
                            theta = pi*s(k).Orientation/180;
                            R = [ cos(theta)   sin(theta)
                                 -sin(theta)   cos(theta)];
                            xy = [a*cosphi; b*sinphi];
                            xy = R*xy;
                            x = xy(1,:) + xbar;
                            y = xy(2,:) + ybar;
                            plot(x,y,'y','LineWidth',2);     
                            hold on;
            end
            hold on
                        for k = AE
                            xbar = s(k).Centroid(1);
                            ybar = s(k).Centroid(2);
                            a = s(k).MajorAxisLength/2;
                            b = s(k).MinorAxisLength/2;
                            theta = pi*s(k).Orientation/180;
                            R = [ cos(theta)   sin(theta)
                                 -sin(theta)   cos(theta)];
                            xy = [a*cosphi; b*sinphi];
                            xy = R*xy;
                            x = xy(1,:) + xbar;
                            y = xy(2,:) + ybar;
                            plot(x,y,'g','LineWidth',2);     
                            hold on;
            end 
0 Commenti
Risposta accettata
  Image Analyst
      
      
 il 12 Nov 2021
        Try this:
logicalIndexes = areas > 3.0 & areas < 200;
AI=find(logicalIndexes); % Indexes within the area range.
AE= find(~logicalIndexes); % Indexes outside the area range.
0 Commenti
Più risposte (1)
  Chunru
      
      
 il 12 Nov 2021
        
      Modificato: Chunru
      
      
 il 12 Nov 2021
  
      Try the following:
 AI=find(3.0<areas & areas<200);
 % AE=find(3.0>areas & areas<200);
 AE=find(3.0>areas | areas<200);
4 Commenti
  Image Analyst
      
      
 il 12 Nov 2021
				@Kristin Aldridge, yes I did.  Perhaps you overlooked it below.  Maybe you could "Accept" it, or at least "Vote" for it.
Vedere anche
Categorie
				Scopri di più su Graphics Object Properties in Help Center e File Exchange
			
	Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


