Can surf or plot3 be modified to vary in x or y but not z?

1 view (last 30 days)
Hi all,
If I generate a grid, e.g.:
x = [1:11];
z = ones(length(x));
surf(z)
xlabel('X');set(get(gca,'xlabel'),'rotation',10);
ylabel('Y');set(get(gca,'ylabel'),'rotation',-10);
zlabel('Z')
to give:
please, how can I vary in the x-direction? Instead of having 11 straight y-axis lines, I'd like each line to be irregular (haphazard profiles), showing variations in x.
I can vary in the z-direction by using, e.g.:
x = [-83,-19,38,61,53,23,-5,-25,-23,-13,-6];
for i = 1:length(x);
z(i,:) = x.*rand(1,length(x));
end
surf(z)
xlabel('X');set(get(gca,'xlabel'),'rotation',10);
ylabel('Y');set(get(gca,'ylabel'),'rotation',-10);
zlabel('Z')
to give:
but I'm having a hard time varying in x or y.
Thanks, Mike.

Accepted Answer

Walter Roberson
Walter Roberson on 7 Jun 2016
You can pass surf() a matrix of X and Y points. For example,
y = sort([-83,-19,38,61,53,23,-5,-25,-23,-13,-6]);
[X, Y] = ndgrid(1:11, y);
X = X + randn(size(X));
Y = Y + randn(size(Y));
Z = X.^2 + exp(sin(Y));
surf(X,Y,Z);
  2 Comments
Mike
Mike on 8 Jun 2016
Hi Walter (or anyone else),
Is there a way to represent X, Y, and Z by just one matrix?
E.g., X, Y, and Z, are each 11 x 11 matrices, and surf(X,Y,Z) generates a 3D surface map. If I have PLAT (an 11 x 11 matrix), surf(PLAT) also generates a 3D surface map. I'd like to add PLAT to (X,Y,Z). Please, how can I represent (X,Y,Z) by an 11 x 11 matrix, or is there a better way to add them?
Thanks!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!