I need to plot two surfaces in plot3

load hyd3d

x2=hyd3d(:,1)
y2=hyd3d(:,2)
z2=hyd3d(:,3)
x3=hyd3d(:,1)
y3=hyd3d(:,2)
z3=hyd3d(:,4)

plot3(x2,y2,z2,‘-b’,x3,y3,z3,‘-k’)
xlabel(‘Temperature (K)’,‘Fontsize’,8)
ylabel(‘Pressure (bars)’,‘Fontsize’,8)
zlabel(‘Mole-fraction’,‘Fontsize’,8)
set(gca,‘fontsize’,10);

hyd3D (161.1 KB)

image

How can I improve the surface representation? I did another plot for another set of simulation results which came out better, Any way to control the surface grid resolution. I do not need to use plot3 but being able to plot to surfaces in one plot based on columns 3 and 4 data from the same file is a must

image

The simulated data for this case were fairly smooth while the data file for the first figure involves a steep change

The function surf would be better for this than plot3, wouldn’t it? Something like this maybe:

x = 0:0.1:10;
y = x';
z1 = x+y+3;
z2 = 10*x+2*y-1;

surf (x,y,z1);
hold on;
surf (x,y,z2)

Thank you very much
X is the same but y and z varies
Can try
Thanks again

load hyd3d

x2=hyd3d(:,1)
y2=hyd3d(:,2)
z2=hyd3d(:,3)
x3=hyd3d(:,1)
y3=hyd3d(:,2)
z3=hyd3d(:,4)

surf(x2,y2,z2,‘-b’)
hold on;
surf(x3,y3,z3,‘-k’)

xlabel(‘Temperature (K)’,‘Fontsize’,8)
ylabel(‘Pressure (bars)’,‘Fontsize’,8)
zlabel(‘Mole-fraction’,‘Fontsize’,8)
set(gca,‘fontsize’,10);

This did not work
Any suggestions?

Explain what “did not work” means. Did it give an error? If so paste it.

Also look at help surf. Your x and y should be vectors and z should be a matrix of appropriate size. From your figures above you look like you have x and y values on a grid so you can try giving them without repetitions to surf.

surf(x2,y2,z2,‘-b’)
hold on;
surf(x2,y2,z3,‘-k’)

Nothing plotted. x,y axis came out as 2 D with no plots

image

This axis does not even have any meaning since value on y should be 50 to 250 and on x 273 to 285

Since your x and y are probably already on a grid, try passing them without repetitions:

surf (unique (x), unique (y), z1)
hold on

Etc.

If you blindly replace plot3 with surf you won’t get good results. Look at the x and y values I passed in my surf example above, and observe that they’re vectors while Z is a matrix.

surf(unique(x2),unique(y2),z2,‘-b’)
hold on;
surf(unique(x2),unique(y2),z3,‘-k’)
image

@Bjoern, you’re repeating the same error. Look very carefully at help surf. Your z needs to be a matrix not a vector. Its order needs to reflect the length of x and the length of y. At the very least, you’ll need to reshape the Z you have into that matrix shape before you call surf. Make sure that each element of Z corresponds to the correct x and the correct y.

Thank you
Sorry for missing that point, which obviously is important
I cannot easily rearrange z into a matrix
I simply have 3 rows in which x and z are rows 1 and 2 and the same for both plots and the row3 on one surface and row4 on another surface

If I return to plot 3 is there any way to fix the problem

If you’re using plot3, the only way to reduce the step size is to sample more x and y points before plotting.

Let me offer this code. You should be able to adapt it to your needs hopefully. Observe the reshape statements before the call to surf:

[xx,yy] = meshgrid (0:0.1:10, 0:0.1:5);
xx = xx(:);  # size 5151x1
yy = yy(:);  # size 5151x1

z1 = 10*xx + 3*yy + 1;
z2 = 3*xx + 5*yy + 1;

#
# assume that the above has already been done by the time you load hyd3d
# so  xx == hyd3d(:,1)
# and yy == hyd3d(:,2)
# and z1 and z2 are hyd3d(:,3) and hyd3d(:,4) respectively
#

x = unique(xx); # length == 101
y = unique(yy); # length == 51

z1 = reshape (z1, numel(y), numel(x));  # size 51x101
z2 = reshape (z2, numel(y), numel(x));  # size 51x101

surf (x, y, z1);
hold on;
surf (x, y, z2);

If you get an error on the reshape statements, then right away you will know that the size of your z vectors are not compatible with the number of x and y points. But your figures above really do look like x and y were generated on a grid, so hopefully this works for you.

Thank you very much
I will try this immediately

load hyd3d

x2=hyd3d(:,1)
y2=hyd3d(:,2)
z1=hyd3d(:,3)
x3=hyd3d(:,1)
y3=hyd3d(:,2)
z2=hyd3d(:,4)

assume that the above has already been done by the time you load hyd3d

so xx == hyd3d(:,1)

and yy == hyd3d(:,2)

and z1 and z2 are hyd3d(:,3) and hyd3d(:,4) respectively

x = unique(x2); # length == 602
y = unique(y2); # length == 602

z1 = reshape (z1, numel(y), numel(x)); # size 602x602
z2 = reshape (z2, numel(y), numel(x)); # size 602x602

surf (x, y, z1);
hold on;
surf (x, y, z2);

xlabel(‘Temperature (K)’,‘Fontsize’,8)
ylabel(‘Pressure (bars)’,‘Fontsize’,8)
zlabel(‘Mole-fraction’,‘Fontsize’,8)
set(gca,‘fontsize’,10);

This did not want to plot and I do not see what is wrong

If the lengths and sizes are all 602 or 602x602 then at least they’re compatible sizes so that’s a good start.

Can you close out of Octave and restart, then run the code?