title: Area Calculation of Surf plot in MATLAB
body: <p>I have irregular 3D cartesian coordinates that make up the one eighth of the surface of a sphere. Thanks to Benoit_11 <a href="https://stackoverflow.com/questions/31544438/matlab-cftool-surface-plot-matrix">Answer to a previously posed question</a> the surface can now be plotted outside of the MATLAB cftool in a normal command line script </p>
  
  <p>Since this point I have been attempting to calculate the area of the surface using the following code patched together from other answers within the area. The code basically calculates the area from the vertices that produce the surface and then sums them all to produce an area. </p>
  
  <pre><code>surface = [ansx1,ansy1,ansz1];
  [m,n] = size(zdata1);
  area = 0;
  for i = 1:m-1
        for j = 1:n-1
            v0_1 = [xdata1(i,j)     ydata1(i,j)     zdata1(i,j)    ];
            v1_1 = [xdata1(i,j+1)   ydata1(i,j+1)   zdata1(i,j+1)  ];
            v2_1 = [xdata1(i+1,j)   ydata1(i+1,j)   zdata1(i+1,j)  ];
            v3_1 = [xdata1(i+1,j+1) ydata1(i+1,j+1) zdata1(i+1,j+1)];
            a_1= v1_1 - v0_1;
            b_1 = v2_1 - v0_1;
            c_1 = v3_1 - v0_1;
            A_1 = 1/2*(norm(cross(a_1, c_1)) + norm(cross(b_1, c_1)));
            area = area + A_1;
        end
  end
  fprintf('\nTotal area is: %f\n\n', area);`
  </code></pre>
  
  <p>However the issue I am having is that the calculated surface over estimates the possible surface. This is due to the removal of NaN from the original matrix and their replacement with 0 this results in the figure 1. Figure 2 provides the only area I would like to calculate </p>
  
  <p><a href="https://i.stack.imgur.com/0EbCL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0EbCL.png" alt="Surface plot when the NaN have been removed"></a></p>
  
  <p><a href="https://i.stack.imgur.com/dgDhU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dgDhU.png" alt="enter image description here"></a></p>
  
  <p>Does anybody have a way of ignoring the zeros within the code provided to calculate the surface area of the data that generates Figure 1?</p>
  
  <p>Thanks in advance</p>