MATLAB: Finding (x,y) points for each Z

surface plot

Hi there,
I'm plotting all my values of the magnitude (in Tesla) of an induced magnetic field against a meshgrid which are the distances.
What I need to know are the distances (x,y) for all magnitudes of my field, but I can't link them togehter. Does someone know how to
acces these values for each z value ?
Thanksin advance
R = linspace(-0.04,0.04,N); % target points [m]

Z = linspace(0.001,0.04,N); % target points [m]
[R2,Z2] = meshgrid(R,Z);
[Br,Bz] = soleno_calcB(R2,Z2,Rin,Rout,Zlow,Zhigh,Itot,Nloop);
surf(R2,Z2,Bz);
title('Induced Magnetic field of detection coil')
xlabel('lateral distance [m]')
ylabel('axial distance [m]')

Best Answer

Bz, R2, and Z2 are already 2D matrices of the same size, so their corresponding values lie at the same index. For example, Bz(i,j) corresponds to R2(i,j) and Z2(i,j). However, If you want to have a linear list then do something like this
B = Bz(:);
RZ = [R2(:) Z2(:)]