How do i put a center of surface in [0 0] coordinates
    7 views (last 30 days)
  
       Show older comments
    
Hi,
I made a 3d surface graph from matrice. I already count a center of this surface, but how do i shift the center of the surface to (0 0) coordinates ? I want to keep z coordinate as it is. Bassicily the origin of x and y must be in the center of surface.
%% Nacteni dat
[Zmeas, dx, wl]= ReadXYZ(measurementFile ,dataFolder);
%Vypocet teziste masky
sizeX = size(Zmeas,2);
sizeY = size(Zmeas,1);
%Vypocet stredu
Zshape = ~isnan(Zmeas);
centerX = 0;
centerY = 0;
cnt = 0;
for m=1:sizeY
    for n=1:sizeX
        if (Zshape(m,n))
            centerX = centerX + n;
            centerY = centerY + m;
            cnt = cnt + 1;
        end
    end
end
centerX = int32(centerX/cnt);
centerY = int32(centerY/cnt);
%Odecteni offsetu a naklonu [piston tip tilt power]
[Zmeas, dx, wl] = RemoveZernikes(Zmeas, Zshape,  [1 1 1], centerX, centerY);
%graf
figure
sl=mesh(wl);
colormap("jet");
xlabel("x"); ylabel("y"); zlabel("z");
title("Odchylky povrchu");
zlim([-.5 .5]);
ylim([0 600]);
xlim([0 600]);
view([135 30]);
%movegui('center');
colorbar
daspect([100 100 1])
2 Comments
  Mathieu NOE
      
 on 13 Jan 2023
				Hello
simply retrieve the center coordinates to your data X,Y coordinates (where are they in your code ?)
X = X - centerX;
Y = Y - centerY;
Answers (1)
  Sarthak
    
 on 7 Mar 2023
        Hi, 
To shift the center of the surface to (0,0), you need to subtract the coordinates of the center point from all the x and y coordinates of the surface points. 
Refer to the code and documentation on meshgrid below- 
x = ((1:sizeX)-centerX)*dx;  
y = ((1:sizeY)-centerY)*dx; 
[X,Y] = meshgrid(x,y); 
Documentation: 
0 Comments
See Also
Categories
				Find more on Surface and Mesh Plots in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

