MATLAB: Issue with different length of columns in a matrix.

matrix manipulation

x,y and z coordinates of a particular image has been saved as a matrix, by using the following code:
[x,y]=find(any(A,3)); % A is the variable which x and y coordinates are saved in.
xyz = [x, y];
xyz(:,1) =xyz(:,1).*0.0003; % multiplied by a calibration factor
xyz(:,2) =xyz(:,2).*0.0003; % -do-
xyz(:,3) = 2; % add the z coordinate to the matrix
save('A_new.mat', 'xyz','-v7','-append') % save the xyz variable
Here is the output which i am getting for the above code:
X extent: 0 to 1576
Y extent: 0 to 1894
Z extent: 0 to 9
Note: z column is added to the x and y column by appending it. My question is why i am getting a low length for the z column (why is it upto 9 instead of being 1576) Can anyone help me to resolve this matter?

Best Answer

You made the extremely common beginner mistake of thinking row,column is the same as x,y. It is NOT. You should have
[y, x] = find(any(A, 3));
Look up find() the in help and you'll see it returns [rows, columns], which is [y, x], not [x,y].