MATLAB: Is there a way in MATLAB to make a boundary and have it skip over data pairs

boundarydataloopMATLAB and Simulink Student Suitenan

I am attempting to make a boundary out of data that is somewhat incomplete. I have been replacing the NaN with 0's, but then the boundary shows up on my graph covering an area I suspect is not accurate. Is there a loop that would allow MATLAB to read the data and make a boundary only out of pairs of data that do not include NaN?
For example, if the data sets are:
m = [0 NaN 2 3 5 NaN]
a = [NaN 2 3 4 5]
I would want to make it so that if I were to make a boundary
am_boundary = boundary(a, m);
then I could use an if loop or something else to only make the boundary out of the third, fourth and fifth data pairs.
Thanks!

Best Answer

Documentation of the function, boundary(x,y), says
  • x and y shall be column vectors
  • x and y shall be of equal length
Try
%%equal length
m = [0 NaN 2 3 5 NaN];
a = [NaN 2 3 4 5, nan ];
%%column vectors
m = reshape( m, [], 1 );
a = reshape( a, [], 1 );
ixnonan = find( not(isnan(m)|isnan(a)) );
k = boundary( a(ixnonan), m(ixnonan) );
k = [ ixnonan(k(1:end-1)); ixnonan(k(1)) ];
am_boundary = [ a(k), m(k) ];
plot( m, a, 'd' )
hold on
plot( m(k), a(k) )