【问题标题】:Range and increment of data in MatlabMatlab中数据的范围和增量
【发布时间】:2014-08-10 06:41:09
【问题描述】:

假设我得到了一个图,我没有它的 x 和 y 向量,但我想从 Matlab 中的图中提取它们。我也有兴趣知道水平和垂直轴(x 和 y 轴)上的数据增量(步长)。 我正在考虑使用:

h=gca             % Get current axis
X=get(h,'xdata');
Y=get(h,'ydata');
stepsize=X(2)-X(1);

但是这些命令会产生一条错误消息: xdata 和 ydata 不是轴的可访问属性。任何关于如何找到任何给定曲线的 x 和 y 向量的建议。

【问题讨论】:

    标签: plot matlab matlab-figure figure curve


    【解决方案1】:

    如果我理解正确,这是你想知道的两件事:

    1. 您有一个包含任意二维线图的图形,您不知道其x_vec, y_vec,您想从图形\轴中提取它们。
    2. 您想获得图中使用的xtickytick 位置。

    您的代码不起作用的原因是因为您试图访问axes 的属性,而您想要访问的是line 的属性(即图中的曲线)。

    要解决您的第一个问题,您可以采用以下方法:

    手动:使用edit plot图形工具可以得到XDataYData线的属性,方式如下:

    Programmatic:您需要找到指向该行的 handle(即指针),然后在 that 句柄上使用您的代码(而不是在 gca ):

    %// If there's only one entity (child) in the axes:
    hLine = get(gca,'Children');
    %// If there's more than one child:
    hChildren = findobj(gca,'Type','line');
    hLine = hChildren(1); %// Or any other logic you need to pick the correct line
    %// Then comes your code:
    xD = get(hLine,'XData'); yD = get(hLine,'YData');
    

    对于第二个问题,你可以使用gca得到XTickYTick

    xT = get(gca,'XTick'); yT = get(gca,'YTick');
    

    要获得步长,我建议只需使用 diff()

    【讨论】:

      【解决方案2】:

      我不确定我是否完全理解您的问题。您的意思是获取曲线的 x 和 y 数据?如果是,那么也许它会帮助研究“ginput”。

      例如,从图形窗口中选取 10 个点可以使用以下命令

      [x,y] = ginput(10)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-08-21
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多