【问题标题】:Draw a circle when we have improvement in line plot in MATLAB R2014b当我们在 MATLAB R2014b 中对线图进行改进时画一个圆圈
【发布时间】:2014-11-05 10:32:07
【问题描述】:

假设我的 GUI(使用 GUIDE 设计)自动升级这样的情节:

我想在改进步骤中有圈子或类似的东西:

我们如何在 MATLAB R2014b 中做到这一点?

附言。

我正在使用这样的代码来更新 GUI 中的绘图:

plot(handles.plot,Value); %%(In a loop)

Value 循环更新。

【问题讨论】:

  • 您绘制的数据看起来如何?你能提供生成情节的代码部分吗?
  • @hitzg 我添加更多信息。
  • @user2991243 那么有什么答案可以帮助您解决问题吗?如果是,请将其标记为已接受。谢谢!

标签: matlab user-interface plot matlab-guide


【解决方案1】:

您可以执行以下操作来检测函数“改进”的点,即导数发生变化时,并在相应位置绘制点:

clear
close all
clc


%// Generate dummy data
t = 1:10;
y = zeros(size(t));

idx1 = 0 <= t & t <= 2;
y(idx1) = 2*t(idx1);

idx2 = 2 < t & t < 3;
y(idx2) = t(idx2);

idx3 = 3 <= t & t <= 5;
y(idx3) = 4;

idx4 = 5 <= t & t <= 8;
y(idx4) = 2*t(idx4);

idx5 = 8 <= t & t <= 10;
y(idx5) = 8;
%======

%// Get indices corrsponding to change in curve
CircleIndices = t(diff(diff(y)) ~= 0) +1

%// Get y-coordinates
yC = y(CircleIndices)

%// plot the curve + the circles
plot(t,y,'r')
hold on
scatter(CircleIndices,yC,40,'k','filled')
hold off

看起来像这样:

这很容易在您的循环/回调中实现。希望对您有所帮助!

【讨论】:

    【解决方案2】:

    如果您想在每个数据点上画一个圆圈,请执行以下操作:

    h = plot(handles.plot,Value,'.-');
    set(h,'MarkerSize',20,'MarkerEdgeColor',[0 0 0]);
    

    第二行将设置点的大小和颜色,尝试给它们你想要的大小。

    如果您想在某些特定数据点上绘制点,请执行以下操作:

    plot(handles.plot,Value);
    hold on
    h = plot(specific_X,specific_Y,'.');
    set(h,'MarkerSize',20,'MarkerEdgeColor',[0 0 0]);
    

    其中 specific_X 和 specific_Y 是向量,其中包含要绘制点的数据点的 x 和 y。

    【讨论】:

      【解决方案3】:

      @R。如果您已经知道所需的要点,Schifini 写了一个很好的答案。如果您希望它是自动的,这个答案会很好:

      我知道您在循环内迭代地向图中添加数据(但实际上,您似乎只是在前一个图上运行......)。如果是这样,你可以这样写:

      plot(handles.plot,Value); %%(In a loop)
      if (Value(end)-Value(end-1))~=(Value(end-1)-Value(end-2))  %% if the slope is changing
        hold on; plot(handles.plot(end-1),Value(end-1), 'ko','Markersize',15);
      end
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2010-12-24
        • 2016-08-03
        • 1970-01-01
        • 2012-12-06
        • 1970-01-01
        • 2015-05-16
        • 2012-11-12
        相关资源
        最近更新 更多