Unrecognized function or variable 'Plot_circle'
Afficher commentaires plus anciens
Hi everybody,
I am new in matlab, and I am trying to make a graph which contains circles of the same radio randomly distributed in a square. I am trying to build it as a function which I can change the number of circles into the square and the radio.
This is the function:
function circle= Generate_circle (x,y,r,N)
%input:
%x=[x1 x2]boundaries of the box
%y=[y1 y2]boundaries of the box
%r: radio of circles
%N: Number of circles
%output
for i=1:1:N
while 1
x1=min(x)+(max(x)-min(x))*rand(1);
y1=min(y)+(max(y)-min(y))*rand(1);
%Define theta range
theta=pi/2*rand(1);
v=2*rand(1)-1;
x2=x1+r*sqrt(1-v^2)*cos(theta);
y2=y1+r*sqrt(1-v^2)*sin(theta);
if x2<=x(2) && x2>=x(1) && y2<=y(2) && y2>=y(1)
break;
end
end
circle(i,1)=x1;
circle(i,2)=y1;
circle(i,3)=x2;
circle(i,4)=y2;
end
Then, I called the function to produce the coordinates and to do the plot as follow:
clc; clear; close all;
x=[0 100];
y=[0 100];
N=11;
r=5;
circle = Generate_circle (x,y,r,N);
Plot_circle(x,y,circle);
It does produce the coordinates, it does not plot it. Can anyone tell me where I am failling in the code. Thank in advance
1 commentaire
Dyuman Joshi
le 14 Jan 2023
Modifié(e) : Dyuman Joshi
le 14 Jan 2023
Try this as your last command -
plot(x,y,circle)
Réponses (1)
clc; % Clear the command window.
%fprintf('Beginning to run %s.m ...\n', mfilename);
close all; % Close all figures (except those of imtool.)
clearvars;
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 18;
% Then, I called the function to produce the coordinates and to do the plot as follow:
x=[0 100];
y=[0 100];
N=11;
r=5;
circle = Generate_circle (x,y,r,N);
% Get centers
xCenters = mean(circle(:, [1,3]), 2);
yCenters = mean(circle(:, [2,4]), 2);
viscircles([xCenters, yCenters], r);
grid on;
axis equal;
function circle = Generate_circle (x,y,r,N)
%input:
%x=[x1 x2]boundaries of the box
%y=[y1 y2]boundaries of the box
%r: radio of circles
%N: Number of circles
%output
for i=1:1:N
while 1
x1=min(x)+(max(x)-min(x))*rand(1);
y1=min(y)+(max(y)-min(y))*rand(1);
%Define theta range
theta=pi/2*rand(1);
v=2*rand(1)-1;
x2=x1+r*sqrt(1-v^2)*cos(theta);
y2=y1+r*sqrt(1-v^2)*sin(theta);
if x2<=x(2) && x2>=x(1) && y2<=y(2) && y2>=y(1)
break;
end
end
circle(i,1)=x1;
circle(i,2)=y1;
circle(i,3)=x2;
circle(i,4)=y2;
end
end
Catégories
En savoir plus sur Ground Truth Labeling dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
