Generating empty interval of points
    3 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
    imola
 am 14 Jan. 2015
  
    
    
    
    
    Kommentiert: Star Strider
      
      
 am 15 Jan. 2015
            Dear All,
I want to generate points in the interval [20,80] and have the interval [40,60] as an empty area. I wrote this code but I don't now how to complete it. I'd appreciate any help.
LB=20;UB=80;
x = LB+(UB-LB)*rand(50,1);
y =LB+(UB-LB)*rand(50,1);
if x>40 | x<60| y>40 | y<60;
  [x]==0;[y]==0;  
  plot(x,y, '.')
but it gives an error.
Regards
0 Kommentare
Akzeptierte Antwort
  Star Strider
      
      
 am 14 Jan. 2015
        This seems to work:
LB=20;UB=80;
x = LB+(UB-LB)*rand(50,1);
y = LB+(UB-LB)*rand(50,1);
idx = [((x > 40) & (x < 60)) | ((y > 40) & (y < 60))];
x(idx) = [];
y(idx) = [];
figure(1)
plot(x, y, '+')
grid
The ‘idx’ variable tests for the conditions and creates a logical vector then used to assign the elements of ‘x’ and ‘y’ to ‘empty’ rather than zero. The plot shows that there are no points in the area you want cleared.
5 Kommentare
Weitere Antworten (1)
  Roger Stafford
      
      
 am 14 Jan. 2015
        Do this:
   LB=20;UB=80;
   x = LB+(UB-LB)*rand(50,1);
   y = LB+(UB-LB)*rand(50,1);
   t = ((x<=40)|(x>=60)) & ((y<=40)|(y>=60));
   x = x(t);
   y = y(t);
   plot(x,y,'.')
Siehe auch
Kategorien
				Mehr zu Interpolation finden Sie in Help Center und File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
