如何用matlab在一个以(2,2)为圆心,r=2的圆内产生1000个随机数,作图,
theta = linspace(0,2*pi,1000);
r = 2;
rrr = r*ones(1,length(theta));
[x0,y0] = pol2cart(theta,rrr);
x0 = x0+2;
y0 = y0+2;
rho = r*rand(1,length(theta));
[x,y] = pol2cart(theta,rho);
x = x+2;
y = y+2;
dd = real(sqrt(x.^2+y.^2));
dmax = max(dd); dmaxid = find(dd==dmax);
dmin = min(dd); dminid = find(dd==dmin);
hold on;
plot(x0,y0,'b:');
plot(x,y,'g.');
plot(x(dmaxid),y(dmaxid),'bo');
plot(x(dminid),y(dminid),'ro');
plot(r,r,'ko');
legend('圆范围','圆内随机点',...
['最远点: ' num2str(dmax)],...
['最近点: ' num2str(dmin)],...
'圆心',2);
axis equal;
axis([-1 5 -1 5]);
hold off;