Concentric Squares with random points

2 Ansichten (letzte 30 Tage)
Lewis HC
Lewis HC am 23 Mai 2020
Kommentiert: Rena Berman am 1 Jun. 2020
Hi to everybody
Someone could I help me how to create a script for two concentric squares so that I have a set of points in the difference of areas?
I have this initial code:
With the last script I reach to create two areas but I need only the points in the difference of areas
Thank you to everybody!
Thank you guys!!!
  2 Kommentare
KSSV
KSSV am 23 Mai 2020
Bearbeitet: KSSV am 23 Mai 2020
You have changed the original question.....even you have unaccepted the accepted answer, even you have deleted your comment where you said thanks for the solution....why? It is not ethical of you.
Rena Berman
Rena Berman am 1 Jun. 2020
(Answers Dev) Restored edit

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

KSSV
KSSV am 23 Mai 2020
clc; clear all ;
% Inner Square
S1 = [-5 -5 ; 5 -5 ; 5 5 ; -5 5] ;
% Outer Square
S2 = [-10 -10 ; 10 -10 ; 10 10 ; -10 10] ;
% Generqate random points
a = -10 ; b = 10 ;
N = 100000 ;
x = (b-a)*rand(N,1)+a ;
y = (b-a)*rand(N,1)+a ;
% poins which lie inside S1
idx = inpolygon(x,y,S1(:,1),S1(:,2)) ;
% plot
x = x(~idx) ; y = y(~idx) ;
plot(x,y,'.b')
  2 Kommentare
Lewis HC
Lewis HC am 23 Mai 2020
Thank you friend!!!
Another question...is it posible get a same squares using for, while, else, etc??...thank you friend!!!
KSSV
KSSV am 23 Mai 2020
Very much possible...

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by