首页 > 解决方案 > 等高线图中水平值的总和

问题描述

我正在尝试计算轮廓内的水平(z轴)值的总和:在此处输入图像描述

我设法获得了轮廓的线条(或边缘),所以我有每条线的限制:

在此处输入图像描述

我想要的是对第二个图中外蓝线内的轮廓 z 轴上的所有级别求和,以将其与蓝线外的值的总和进行比较。有没有办法做到这一点?我到目前为止的代码是:

   C = contourc(f, t, abs(tfr));

%extracts info from contour    
    sz = size(C,2);     % Size of the contour matrix c
    ii = 1;             % Index to keep track of current location
    jj = 1;             % Counter to keep track of # of contour lines

    while ii < sz       % While we haven't exhausted the array
        n = C(2,ii);    % How many points in this contour?
        s(jj).v = C(1,ii);        % Value of the contour
        s(jj).x = C(1,ii+1:ii+n); % X coordinates
        s(jj).y = C(2,ii+1:ii+n); % Y coordinates
        ii = ii + n + 1;          % Skip ahead to next contour line
        jj = jj + 1;              % Increment number of contours
    end

标签: matlabplotcontour

解决方案


因此,在您运行问题中的代码后,您将获得数组中每个轮廓的坐标S。假设你有变量ft形式f = 94:0.1:101t = 0:1000或类似的,你想求和的那个值是abs(tfr)你应该能够使用的

[fg, tg] = meshgrid(f,t)
is_inside = inpolygon(fg,tg, S(1).x, S(1).y)
integral = sum(abs(tfr(is_inside))

对于S. 有关更多示例,请参阅inpolygon的帮助。您可以~is_inside用于曲线外的点


推荐阅读