how to create an array of ones with some zeros delimited by an ellipse?
2 views (last 30 days)
Show older comments
I need to create an array with ones inside an ellipse and zeros outside it. The matrix has dimensions of NxM = 91x361. This matrix will be plotted polarly and the ellipse must be completely contained within the matrix.
1 Comment
Walter Roberson
on 3 Aug 2021
One approach is to use an Ellipse ROI object https://www.mathworks.com/help/images/ref/images.roi.ellipse.html and createMask() from it.
This has the advantage of being fairly customizable as to center and axes lengths.
It is, though, overly complicated if you just happen to have the simple case of the ellipse being aligned with the x y planes.
Do you happen to be looking for the largest x y aligned ellipse that will fit completely inside your N x M ?
Answers (1)
Rik
on 3 Aug 2021
I'm going to ignore the part where you want to plot a cartesian object with polar coordinates.
You can either use ndgrid or meshgrid to generate a coordinate grid. Then you need to google the equation for an ellipse, after which it should be obvious how to adjust it to return all points inside the ellipse, instead of only the points exactly on the array.
To satisfy your requirement of each pixel being entirely inside the ellipse you can use the corners of each pixel and mark only the pixels if all four corners are inside.
Feel free to post a follow-up question in a comment if your have trouble implementing a specific step.
4 Comments
See Also
Categories
Find more on Polar Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!