MATLAB Answers

How to plot the elements of a matrix with a specific coordinates and specified the region in matlab?

2 views (last 30 days)
Mavis Lee
Mavis Lee on 29 Oct 2019
Commented: Mavis Lee on 29 Oct 2019
Hello everybody. I need your help about a problem that I have in matlab.
For instance lets say that I have a Matrix X = [1,2,3,4,5,6,7,8] with different coordianates as shown above. For example, Element 1 of the matrix = (0,1).
And, I would like to set the regions as shown in below.
Is it possibles to create something like this?
Thank you in advance.

  2 Comments

Mavis Lee
Mavis Lee on 29 Oct 2019
Hi Darova.
It's ok with or without the color.
I just want to set few regions inside the Circle. For example, the region 1 (yellow color) is located within 1, 5 and 2 as shown in figure below.
It is possible to set the region using the coordinates of point 1, 5 and 2 or have other better solution?
Thank you in advance.

Sign in to comment.

Accepted Answer

darova
darova on 29 Oct 2019
Maybe inpolygon
n = 100;
t = -linspace(0,2*pi,n)+pi/2;
x = cos(t);
y = sin(t);
x0 = 0.5; % point to check
y0 = 0.7;
nd = 8; % divide circle in 8 parts
for i = 1:nd
ii = (i-1)*n/nd+1 : i*n/nd;
ii = round(ii);
if inpolygon(x0,y0,[x 0],[y -11]) % segment of a circle and (0,-1) point
sprintf('point in R%d region',i)
end
end

  3 Comments

Mavis Lee
Mavis Lee on 29 Oct 2019
Hi,
It is possible to display the region in diagram as it only showed me these result.
Thank you in advance.
ans =
'point in R1 region'
ans =
'point in R2 region'
ans =
'point in R3 region'
ans =
'point in R4 region'
ans =
'point in R5 region'
ans =
'point in R6 region'
ans =
'point in R7 region'
ans =
'point in R8 region'
>>
darova
darova on 29 Oct 2019
My bed, sorry
clc,clear
n = 100;
t = -linspace(0,2*pi,n)+pi/2;
x = cos(t);
y = sin(t);
x0 = 0.5; % point to check
y0 = 0.2;
nd = 8; % divide circle in 8 parts
cla
plot(x,y,'.b')
hold on
plot(x0,y0,'or')
i1 = 1; % start index of a section
for i = 1:nd
i2 = round(i*n/nd); % end index of a section
xx = [x(i1:i2) 0]; % region of interest
yy = [y(i1:i2) -1];
p = patch(xx,yy,'','FaceCOlor',rand(1,3));
if inpolygon(x0,y0,xx,yy) % segment of a circle and (0,-1) point
sprintf('point is in R%d region',i)
plot(x0,y0,'or')
end
pause(0.5)
% delete(p)
i1 = i2;
end
hold off

Sign in to comment.

More Answers (0)

Sign in to answer this question.