Suppose I want to plot f(x,y,z) = x^2
using the scatter3
function of GNU Octave.
My code is
x = [1,2,3,4];
y = [1,2,3,4,5];
z = [1,2,3,4,5,6];
for xi = 1:4
for yi = 1:5
for zi = 1:6
a(xi,yi,zi) = x(xi) * x(xi);
endfor
endfor
endfor
[xx yy zz] = meshgrid(x,y,z);
scatter3(xx(:), yy(:), zz(:), [], a(:),'fill');
xlabel('x')
ylabel('y')
zlabel('z')
colormap(rainbow)
colorbar()
I am getting the above plot, which shows that the function changes with
y
(it is actually y^2
), and is a constant w.r.t. x
. Am I doing something wrong? Since a(xi,yi,zi) = x(xi) * x(xi)
, should not I get a = x^2
instead, due to the index xi
?
I have labelled the three axes.
I am using Octave 4.2.2 in Ubuntu 18.04.