【问题标题】:How to merge results of multiple viscircles in MATLAB如何在 MATLAB 中合并多个 viscircle 的结果
【发布时间】:2016-11-23 13:12:47
【问题描述】:

我正在尝试使用 viscircles 在函数中绘制一个圆,然后稍后返回该函数绘制另一个圆,如下图所示:

目前,我只能使用这些代码行绘制单个圆圈:

figure
center = [numberX numberY];
xlim([-0.1 10.1])
ylim([-0.1 10.1])
axis square
artwork = viscircles(center,size,'Color',colorControl)

在绘制第一个viscircles 后,控制回滚到提示函数以获取下一个viscircles 的数据,但是当它回到绘图时,原始viscircles 被覆盖,即使我尝试过使用hold on。任何建议将不胜感激。

【问题讨论】:

  • 您可以编辑问题以添加更多代码行吗?这可以帮助其他人提出建议。
  • 谢谢 rayryeng!该代码非常适合新添加新圈子。我知道我没有在问题中说得很清楚,但我实际上是在尝试绘制多种颜色的圆圈。使用您的代码,每次添加新圆圈时,所有圆圈都会变成新颜色。有没有解决的办法?我尝试复制您用于中心和大小变量的格式,但 Matlab 对此不太满意。
  • @LouisRichard 我会尽快修改我的帖子。我现在不在家。很高兴代码到目前为止有效!

标签: matlab plot geometry


【解决方案1】:

viscircles 默认情况下将刷新图形并仅绘制由您提供的输入指定的圆圈,因此hold on 将不起作用。

您可以改为将附加添加到您的数据中,以便在每次提示输入新数据时显示原始数据,然后显示一个新圆圈。

因此,做这样的事情。假设您有一个名为 getNewCenter 的函数,它返回一个新中心、圆的大小和颜色,以及包含要显示的中心及其大小的矩阵:

centers = [];
sizes = []; % Matrices that contain the centers and sizes

while true % Keep iterating...

    [numberX, numberY, size, colorControl] = getNewCenter; % Get new center, size and colour

    % Add to the data
    centers = [centers; numberX numberY];
    sizes = [sizes; size];

    % Plot the circles
    xlim([-0.1 10.1]);
    ylim([-0.1 10.1]);
    axis square;
    artwork = viscircles(centers, sizes, 'Color', colorControl);
end

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-20
    • 1970-01-01
    • 2018-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-19
    相关资源
    最近更新 更多