I have a rational function $\phi: [0,1]^3 \to \mathbb R^3$ (A NURBS, to be precise) and I want to visualize the image of $\partial [0,1]^3$ using a surface plot (patch, for example). To do this I have chosen equidistant discretisation along each dimension and formed a meshgrid from this:
Nx = 50;
Ny = 2;
Nz = 20;
tx = linspace(0, 1, Nx);
ty = linspace(0, 1, Ny);
tz = linspace(0, 1, Nz);
[mx, my, mz] = meshgrid(tx,ty,tz);
Now I have implemented a function wich gives me a $3\times (Nx\cdot Ny\cdot Nz)$-matrix $M$ with the values $M_{:, i} = \phi(mx_i, my_i, mz_i)$ using linear indexing. Plotting this as a point cloud gives me a good gist of the figure:

Now I'd rather like to have a "solid" plot of the shape by plotting a patch for each of the six sides of the deformed cube. Is there a nice way to do this without having to manually think through the indexing?
Finally, I've accomplished my goal by individually
surf-plotting each face of the transformed cube:After looking at the docs of
surfI foundsphere(n)to produce an input forsurfwhich would render the unit sphere and looked into it:surf(X,Y,Z)where all are matrices of the same size produces the surface with these points preserving the rectangular topology. This leads to the following code:And then after evaluation of
xinto the variablesPx, PyandPz:This produces the following image:
Note that the red line is where two faces meet inside the figure.