MATLAB: Do the figures created using ISOSURFACE and SURF not match up in MATLAB 7.1(R14SP3)

isosurfaceMATLABmeshgridrotationsurfvector

I want to analyze my volume data and use SURF and ISOSURFACE functions for this purpose. I execute the following commands in MATLAB to display my data:
load my_volume_data
p=0.98;
figure(1);
clf; isosurface(X, Y, Z, V, p);
xlabel('X'); ylabel('Y'); zlabel('Z');
title('Arch in X-Z plane in +Z-direction')
%view([0 0]);title('X-Z plane: Arch in +Z-direction')%uncomment to view X-Z plane
figure(2);
clf; surf(Z, X, squeeze(V(:,find(Y==0),:)));%obtain the X-Z data by setting Y=0.
xlabel('Z'); ylabel('X'); zlabel('scalar value');
title('Arch in -Z-direction');
%view([90 -90]);title('X-Z plane: Arch in -Z-direction')%uncomment to view X-Z plane
The direction of the Z-axis from the SURF plot is opposite to the direction of the Z-axis in the figure obtained from the ISOSURFACE plot.

Best Answer

This is the expected behavior when using the SURF and ISOSURFACE functions to display volume data in MATLAB 7.1 (R14SP3).
This behavior is due to the following command in the code above:
surf(Z, X, squeeze(V(:,find(Y==0),:)));
This behavior is due to the SURF plot interpreting data as obtained by the MESHGRID function. The documentation for the SURF plot says in part:
surf(X,Y,Z) creates a shaded surface using Z for the color data as well as surface height. X and Y are vectors or matrices defining the x and y components of a surface. If X and Y are vectors, length(X) = n and length(Y) = m, where [m,n] = size(Z). In this case, the vertices of the surface faces are (X(j), Y(i), Z(i,j)) triples.
Since the variables X and V are vectors, the vertices of the surface faces are (X(j), Y(i), Z(i,j)) triples. In order to understand this better, consider a simple 2D example in MATLAB:\n
x=[0:2];y=[0:3]; % example of vectors used as inputs to the SURF plot
[xdata,ydata] = meshgrid(0:2,0:3) %view of how SURF interprets these vectors
z=[1 1 1 ;1 0 0 ;0 0 1;1 1 1]%sample data
The output is:
xdata =
0 1 2
0 1 2
0 1 2
0 1 2
ydata =
0 0 0
1 1 1
2 2 2
3 3 3
z =
1 1 1
1 0 0
0 0 1
1 1 1
Suppose we want to extract the z-data when x=2. We would assume that the following equation in MATLAB will result in the correct output:\n
z(find(x==2),:)
The output is:
ans =
0 0 1
As seen, the 3rd row of z is obtained, when in fact we need the 3rd column of z. This is because in the vector x, the third element is 2. Since by default the first dimension implies rows and the second dimension implies column in MATLAB, therefore, the third row is obtained. To obtain the correct results, execute the following command in MATLAB:\n
z(:,find(x==2))
The output is:
ans =
1
0
1
1
The above result is as expected. To display the volume data properly and understand this issue better, execute the following commands in MATLAB:\n
load my_volume_data
p=0.98;
V = V(41:81,1:81,1:121); %obtain half of the volume data
Y = Y(41:81);
[xdata,ydata,zdata] = meshgrid(X,Y,Z);%obtain meshgrid data from vectors
figure(1);
isosurface(xdata,ydata,zdata,V,p);
xlabel('X'); ylabel('Y'); zlabel('Z');
%view([0 0]);title('X-Z plane: Arch in +Z-direction')%uncomment to view X-Z plane
figure(2)
slice(xdata,ydata,zdata,V,[],0,[]);% obtain the slice though V when y=0.
xlabel('X'); ylabel('Y'); zlabel('Z');
shading interp
figure(3)
Vnew = squeeze(V(find(Y==0),:,:)); % notice how the FIND term is in the
%first dimension instead of the second dimension
surf(Z,X,Vnew);
shading interp
xlabel('Z'); ylabel('X');
%view([90 -90]);title(''X-Z plane: Arch in +Z-direction')%uncomment to view X-Z plane
To obtain more information on the SURF, SLICE and MESHGRID functions, refer the links below:
https://www.mathworks.com/help/matlab/ref/meshgrid.html