The challenge was more math than MATLAB itself.
Here is the solution:
close all;
% defining the plane:
N = 2:4; % normal vector to the plane
P0 = 5:7; % point on the plane
d = -N*P0';
x = -5:5;
y = x;
[x, y] = meshgrid(x, y);
z = -(N(1).*x + N(2).*y + d)./N(3);
% Coordinate transformation matrix from the plane z = 0, to
% the plane N(1)*x + N(2)*y +N(3)*z + d = 0.
M = eye(4);
M(3, 1) = -N(1)/N(3);
M(3, 2) = -N(2)/N(3);
M(3, 4) = -d/N(3);
M(3, 4) = M(3, 4)*1.01; % to ease viewing the contour lines and text
% function to be projected on the plane:
f = sqrt(x.^2 + y.^2 + z.^2)*0.1;
figure;
hold on;
surface(x, y, z);
xlabel("x");
ylabel("y");
zlabel("z");
shading interp;
cb = colorbar;
cb.Label.String = "z";
cb.Limits = [min(z, [], "all") max(z, [], "all")];
HGT = hgtransform();
HGT.Matrix = M;
Warning: The new value for the Matrix property may cause rendering problems.
hold on;
contour(x, y, f, "k", "ShowText", "on", "Parent", HGT);
grid on;
box on;
view(120, 60);
I don't know what's the problem with this transformation (i.e. the warning message).
Note: the above only works for projections over a plane.