MATLAB: Connect a group of lines into surface plot

plot3surface plot

I have some ggroup of experimental data for x, y and z. x and y are vectors, and z is a group indicator. For example:
x = [(1:16)', (20:35)']; %size 2 x 16
y = [(20:35)', (100:115)']; % size 2 x 16
z = [3, 4]; %size 2 x 1
plot3(z,x,y);
I get the graph as the following:
2020-02-05 18_43_13-Figure 1.png
Is it possible to plot it as a surface?

Best Answer

Just use the surf (or mesh) function:
x = [(1:16)', (20:35)']; %size 2 x 16
y = [(20:35)', (100:115)']; % size 2 x 16
z = [3, 4]; %size 2 x 1
figure
surf(z,x,y);
If you want ā€˜zā€™ as the dependent variable, however, you will need to create it as:
z = ones(size(x(:,1)))*z;
since it would then have to be a matrix.
Related Question