How can I plot multiple rectangles (or circles) using the rectangle function without using a for loop?
19 次查看(过去 30 天)
显示 更早的评论
I need to plot multiple circles using the built in rectangle function. I have matrices that contain the x and y coordinates of the points that I want the center of my circle to be on. d is the diameter of the circles. The code I am using is below. I want to plot the circles without using the for loop in order to save time.
for i = 1 : size(x,1)
pos = [x(i)-d/2, y(i)-d/2, d, d];
rectangle('Position',pos,'Curvature',[1 1],'FaceColor','c','EdgeColor','k','LineWidth',1);
end
0 个评论
采纳的回答
Athul Prakash
2020-4-3
I don't think there is a way to 'vectorize' this code, you can't eliminate this for loop and achieve much of a speed up. But how about the following:
If rendering the plot is the time-consuming part of your code, you may try generating plot points for all circles into the same X,Y arrays and calling plot() once at the end. Intead of the rectangle function, each circle can be a set of enough number of points which you can calculate using the circle equation.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Formatting and Annotation 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!