I have two shapes and I want to color the area between them
The first shape is a circle of Radius R=10 for example and with center (0,0), and the second shape is a random shape but surrounds the cirle and may have communs points, but it is impossible to have points inside the circle (as in the picture).
As example for real data that I have:
load('data.mat'); % load the coordinates of the second random shape represented as 'xfs' and 'yfs'
%%%%%%%%% create the circle %%%%%%%%%%
R = 10; C = [0. 0.] ;
xcf = C(1)+R*cos(linspace(0,2*pi,length(xfs))) ;
ycf = C(2)+R*sin(linspace(0,2*pi,length(xfs))) ;

6 件のコメント

Star Strider
Star Strider 2021 年 4 月 22 日
It is not possible to read the attached file. I tried several different ways to open it and all attempts failed.
Try saving it again as a .mat file, rather than giving it a .m suffix.
Khoder Makkawi
Khoder Makkawi 2021 年 4 月 22 日
Ok sorry it was my fault, could you try now please
Matt J
Matt J 2021 年 4 月 22 日
The data.mat file does not contain data resembling the posted shape.
Khoder Makkawi
Khoder Makkawi 2021 年 4 月 22 日
the data file contain the x and y coordinates for the points of the posted shape. For each value in "x" it corresponds to a value in "y" at the same index.
Matt J
Matt J 2021 年 4 月 22 日
Let's plot it right now:
load(websave('t','https://www.mathworks.com/matlabcentral/answers/uploaded_files/592700/data.mat'))
scatter(xfs,yfs)
Khoder Makkawi
Khoder Makkawi 2021 年 4 月 22 日
It was the wrong data I saved in the second time sorry again.
These are the right coordinates.
I modified the file.

サインインしてコメントする。

 採用された回答

Matt J
Matt J 2021 年 4 月 22 日
編集済み: Matt J 2021 年 4 月 22 日

0 投票

load(websave('t','https://www.mathworks.com/matlabcentral/answers/uploaded_files/592785/data.mat'))
R = 10; C = [0. 0.] ;
xcf = C(1)+R*cos(linspace(0,2*pi,length(xfs))) ;
ycf = C(2)+R*sin(linspace(0,2*pi,length(xfs))) ;
shpOuter=polyshape(xfs,yfs);
shpInner=polyshape(xcf,ycf);
Warning: Polyshape has duplicate vertices, intersections, or other inconsistencies that may produce inaccurate or unexpected results. Input data has been modified to create a well-defined polyshape.
plot(shpOuter,'FaceColor','none');
hold on
plot(shpInner,'FaceColor','none');
plot(subtract(shpOuter,shpInner))
hold off

5 件のコメント

Khoder Makkawi
Khoder Makkawi 2021 年 4 月 22 日
Hello Matt,
I am receiving this message: "Undefined function or variable 'polyshape'."
So could you send me the function please.
Matt J
Matt J 2021 年 4 月 22 日
編集済み: Matt J 2021 年 4 月 22 日
Khoder Makkawi
Khoder Makkawi 2021 年 4 月 22 日
That's exactly what I want, but the problem is that I have R2016a so there is no solution to have this function?
Matt J
Matt J 2021 年 4 月 22 日
No. You should upgrade. There have been lots of important new features added since R2016a.
Khoder Makkawi
Khoder Makkawi 2021 年 4 月 22 日
ok Thank you I will try to upgrade.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeElementary Polygons についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by