how to set concentric rectangle dataset?
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
z cy
el 30 de Dic. de 2019
Editada: Image Analyst
el 31 de Dic. de 2019
I want that the number of each color data point can be changed
10 comentarios
Adam Danz
el 31 de Dic. de 2019
Instead of deleting some of the points, you could replace those coordinates with a new set of random coordinates. That could be set up within a while-loop where you keep replacing values that meet a set criteria until all of the points meet the requirements.
Respuesta aceptada
Image Analyst
el 31 de Dic. de 2019
Try this:
% Define parameters.
numPoints = 1000000; % Something way bigger than you think you'll need.
n1 = 200;
n2 = 300;
n3 = 400;
% Generate numPoints (x,y) locations.
x = 3 * rand(numPoints, 2) - 1.5;
y = 3 * rand(numPoints, 2) - 1.5;
% plot(x, y, '.');
%-----------------------------------------------------------
% Get the inner zone points and plot them.
zone1 = (abs(x) < 0.5) & (abs(y) < 0.5); % Inner zone
zone1i = find(zone1, n1); % Get the actual indexes for the first n1 points.
x1 = x(zone1i);
y1 = y(zone1i);
hold on;
plot(x1, y1, 'ro');
%-----------------------------------------------------------
% Get the outer zone points and plot them.
zone3 = ~((abs(x) < 1) & (abs(y) < 1)); % Outer zone
zone3i = find(zone3, n3); % Get the actual indexes for the first n3 points.
x3 = x(zone3i);
y3 = y(zone3i);
hold on;
plot(x3, y3, 'b^');
%-----------------------------------------------------------
% Get the ring zone points and plot them.
zone2 = ~(zone3 | zone1); % Ring zone is everything except those in zone 1 or zone 3.
zone2i = find(zone2, n2); % Get the actual indexes for the first n2 points.
x2 = x(zone2i);
y2 = y(zone2i);
hold on;
plot(x2, y2, 'g+');
grid on;
axis equal;
0 comentarios
Más respuestas (1)
Image Analyst
el 31 de Dic. de 2019
Editada: Image Analyst
el 31 de Dic. de 2019
In your code, see how n1 and n2 are passed into randn():
r = unifrnd(-0.9,0.9,[1,n1]);%r= r(randperm(length(r)));
t = unifrnd(-0.5,0.5,[1,n1]);%t= t(randperm(length(t)));
x = r + noise1*randn(1,n1);
y = t + noise1*randn(1,n1);
z = sqrt(noise2)*randn(fea_n,n1);
data1 = [x; y;z];
r = unifrnd(-1.9,1.9,[1,n1*2.5]);
t = unifrnd(-1.5,1.5,[1,n1*2.5]);
b = [r;t];
b(:,(abs(b(1,:)) <=1.15)+(abs(b(2,:))<0.65) ==2) =[];
n2 = size(b,2);
x = b(1,:) + noise1*randn(1,n2);
y = b(2,:) + noise1*randn(1,n2);
z = sqrt(noise2)*randn(fea_n,n2);
data2 = [x;y;z];
So you say "I want that the number of each color data point can be changed" so just change the value of n1 to change the number of points. You didn't show how you assigned it, but you must have assigned it before this code or else the code would not have worked.
2 comentarios
Image Analyst
el 31 de Dic. de 2019
Editada: Image Analyst
el 31 de Dic. de 2019
Do you need to set a specific number for each color of marker, like a specified n1 for red, n2 for green, and n3 for blue? If so, you can just generate a new point and keep it or reject it if it falls in the proper "zone". So I'd just call rand() to get like a few million points. Then get 3 logical vectors to determine which rows are in zone1, zone2, or zone3. Then extract those rows and crop them to just the first n1, n2, or n3 rows. Then plot. See fully worked out code in my other answer on this page.
Ver también
Categorías
Más información sobre Graphics Performance en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!