-1

I would like to achieve a 3D surface plot. My outputs are as follows.

For a particular value of z, I get y for each value of x (x ranges like 0:0.1:1.4).

Then I vary z and, for the same range of x, I get y values.

The result can be visualised as 2D plots at discrete z values, consisting of the range of x and its corresponding y. Here is my original plot:

plot

I would like to create a 3D surface plot instead, like a blanket wrapped over the above 2D plots.

Wolfie
  • 27,562
  • 7
  • 28
  • 55
Gopalpur
  • 121
  • 1
  • 4
  • 14
  • 2
    It is not as easy as you imagine to follow your thoughts / description. Please add your code and an example of input/output (see [ask]). This will allow us to help you easier – Irreducible Oct 26 '17 at 08:40
  • 3
    _I would like to create a 3D plot. I_ You need to specify _how_ you want that plot. A set of x-y curves in 3D space, one for each z? A surface y=f(x,z)? An image y=f(x,z), where y is shown as different colors on the x,z plane? Are the x values always the same for each z? – Luis Mendo Oct 26 '17 at 09:11
  • @LuisMendo: Ya, set of xy curves in 3D space one for each z. a surface. yes x values always the same for each z – Gopalpur Oct 26 '17 at 09:48
  • The image you added clarifies it a bit. What's the _z_ axis in that image? From your description it would seem it's the one label with letters, is it? – Luis Mendo Oct 26 '17 at 09:59
  • @LuisMendo: Ya. z axis is with labels. X axis is same for all the individual plots in the figure. Could you pls let me know how to get surface plot? Thanks – Gopalpur Oct 26 '17 at 10:32

1 Answers1

5

Here's an example for the two types of plots:

figure
hold on
grid on
view(30,40)
x = 0:.01:4;
z = .3:.3:3;
y = NaN(numel(x), numel(z));
for k = 1:numel(z)
    y(:,k) = abs((4-x).*sin(x/(1+z(k)))); % compute a vector as function output
        % for input vector x, for each z. Store as a column in matrix y
    plot3(x,repmat(z(k),size(x)),y(:,k)) % plot in 3D space
end

figure
surf(x,z,y.','edgecolor','none') % surface plot
view(30,40)
grid on

enter image description here

enter image description here

Luis Mendo
  • 110,752
  • 13
  • 76
  • 147
  • Thanks a lot for your reply. It really helped. Highly appreciated. – Gopalpur Oct 27 '17 at 06:06
  • Hey, When I add labels, they are not aligned to the axis. Do you have any idea why it is? – Gopalpur Oct 27 '17 at 06:41
  • @KGV How are you adding the labels, exactly? – Luis Mendo Oct 27 '17 at 09:13
  • Just like the following. Similar way as how we do for 2d plots. surf(x,z,y.','FaceAlpha',1.0) xlabel('Non-Dimensional Number (k_0a)') ylabel('Non-Dimensional Horizontal Force (HF_P)') zlabel('Non-Dimensional Porous Parameter (G_S)') view(30,40) grid on. I am actually expecting labels along their respective axis. – Gopalpur Oct 27 '17 at 10:13