1function z = cvmgt(x, y, p) 2%CVMGT Conditional merge of two vectors 3% 4% z = CVMGT(x, y, p) return a vector z whose elements are x if p is true 5% and y otherwise. p, x, and y should be the same shape except that x 6% and y may be scalars. CVMGT stands for conditional vector merge true 7% (an intrinsic function for the Cray fortran compiler). It implements 8% the C++ statement 9% 10% z = p ? x : y; 11 12 z = zeros(size(p)); 13 if isscalar(x) 14 z(p) = x; 15 else 16 z(p) = x(p); 17 end 18 if isscalar(y) 19 z(~p) = y; 20 else 21 z(~p) = y(~p); 22 end 23end 24