等高线图水平值的总和

summation of level values from contour plot

我正在尝试计算等高线内水平(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

因此,在您 运行 问题中的代码之后,您拥有数组 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