The answer seems to be simple, but I'm at a dead end. I have an Nx3 matrix matrix, where the 1st and 3rd columns are the XY and Z coordinates for the nth element. I want to calculate the distance from the beginning to the element. In a non-vectorized way, this is easy.
distance = norm ([xyz]);
or
distance = sqrt (x ^ 2 + y ^ 2 + z ^ 2);
However, in a vectorized form it is not so simple. When you pass a matrix back to normal, it no longer returns the Euclidean length.
distance = norm (matrix); % does not work.
and
distance = sqrt (x (:, 1). * x (:, 1) + y (:, 2). * y (:, 2) + z (:, 3). * z (:, 3)); % just seems dirty
Is there a better way to do this?