Defining surfaces not only in terms of z

I have three different surfaces and I want to display them all in one drawing.

The problem is that I have one surface defined in terms of z (which means I got the x and y values ​​and a grid that gives the z values ​​for each combination) and two others that are defined in terms of x. This means that there are different z-values ​​for the same x, y-pair.

My idea:

figure
surf(x,y,zgrid)
hold on
surf(x,ygrid,z)
surf(x,ygrid2,z)
hold off

      

I was hoping MATLAB would handle this on its own, but it doesn't. Do you have any ideas how to get the results you want? I want to show them all in one graph to show the cross sections.

Here's an image of how it should look more or less:

enter image description here

If there is a nicer way to show this, please let me know.

+3


source to share


1 answer


You have not indicated what exactly is going wrong, but I would venture to assume that you got an error similar to the following when you tried to build your second surface:

Error using surf (line 82)
Z must be a matrix, not a scalar or vector.

      

I assume that your variables x

, y

and z

are vectors, not matrices. The function surf

allows you to enter inputs x

and y

, which are then expanded into matrices using meshgrid

. It doesn't do this for input z

.

Your best bet, in my opinion, is to just use matrices for all your inputs. Here's an example where I do it (using meshgrid

) to plot three surfaces of a cube:



% Top surface (in z plane):
[x, y] = meshgrid(1:10, 1:10);
surf(x, y, 10.*ones(10), 'FaceColor', 'r');
hold on;

% Front surface (in y plane):
[x, z] = meshgrid(1:10, 1:10);
surf(x, ones(10), z, 'FaceColor', 'b');

% Side surface (in x plane):
[y, z] = meshgrid(1:10, 1:10);
surf(ones(10), y, z, 'FaceColor', 'g');
axis equal

      

And here's the plot:

enter image description here

+3


source







All Articles