您可以使用轻松完成此操作viscircles http://www.mathworks.com/help/images/ref/viscircles.html(这需要图像处理工具箱 http://www.mathworks.com/products/image/)但是我认为输出实际上并不是您所期望的。
radius = 0.3524;
dots = plot(timeline, Origdata, '.');
hold on
for k = 1:numel(dots)
plotdata = get(dots(k));
centers = [plotdata.XData(:), plotdata.YData(:)];
% Ensure the the colors match the original plot
color = get(dots(k), 'Color');
viscircles(centers, radius * ones(size(centers(:,1))), 'Color', color);
end
之所以看起来像这样是因为你的 X 数据是very相对于您的 y 数据紧密相连,并且为了使圆圈显示为圆圈,我强制轴的 x 和 y 缩放比例相等(axis equal
)
Edit
如果你只想要radius
为了相对于 y 轴(距离),那么我们实际上需要绘制具有 x 和 y 半径的椭圆。我们想要缩放“x 半径”以使其显示为圆形,而不管您的真实轴纵横比如何,这样的东西实际上可以做到这一点。
下面代码的技巧是设置数据和绘图纵横比(pbaspect
and daspect
)到手动。这确保了轴的纵横比在缩放、调整大小等过程中不会改变,并确保我们的“圆圈”保持圆形。
dots = plot(timeline, Origdata, '.');
drawnow
% Force the aspect ratio to not change (keep the circles, as circles)
pbaspect('manual')
daspect('manual')
hold on
aspectRatio = daspect;
t = linspace(0, 2*pi, 100);
t(end+1) = NaN;
radius = 4.3524;
% Scale the radii for each axis
yradius = radius;
xradius = radius * aspectRatio(1)/aspectRatio(2);
% Create a circle "template" with a trailing NaN to disconnect consecutive circles
t = linspace(0, 2*pi, 100);
t(end+1) = NaN;
circle = [xradius*cos(t(:)), yradius*sin(t(:))];
for k = 1:numel(dots)
x = get(dots(k), 'XData');
y = get(dots(k), 'YData');
color = get(dots(k), 'Color');
% Center circle template at all points
circles = arrayfun(@(x,y)bsxfun(@plus, [x,y], circle), x, y, 'uni', 0);
circles = cat(1, circles{:});
plot(circles(:,1), circles(:,2), 'Color', color)
end
只是为了演示,如果我们将圆半径增加到 4.3524,我们可以更好地看到圆。
这适用于所有调整大小等。