等高线图的水平值总和

时间:2018-05-04 10:37:56

标签: matlab plot contour

我正在尝试计算轮廓内水平(z轴)值的总和:enter image description here

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

enter image description here

我想要的是将第二个图中外部蓝线内轮廓的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

1 个答案:

答案 0 :(得分:2)

因此,在运行问题中的代码后,您将获得数组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用于曲线外的点