MATLAB How Can I Convert a 2D Plot to a 3D Plot in MATLAB?

  • Thread starter Thread starter adnan jahan
  • Start date Start date
  • Tags Tags
    3d Matlab Plot
AI Thread Summary
To convert a 2D plot in MATLAB to a 3D plot, the function `plot3` is recommended. The user initially attempts to plot the equation s = x^2 + y^3 in 2D and seeks to extend it into 3D by incorporating a z-axis ranging from -1 to 1. The correct approach involves defining the z component separately and ensuring that the dimensions of the matrices used in the plot function match. The user encounters an error related to matrix dimensions when trying to plot a parabolic curve in 3D. To resolve this, it is essential to ensure that the vectors for x, y, and z are compatible in size. The discussion emphasizes the need for proper matrix manipulation to achieve the desired 3D visualization.
adnan jahan
Messages
93
Reaction score
0
Dear Friends

I have made 2D plot in MATLAB and want to convert it in 3D can you give me any suggestions please.

if
s=x^2+y^3
x=linspace(0,2);
plot(y,s,'b')
this gives the plot of 2D
I want to make it in 3D for any value of z axis(-1 to 1)
what changes i have to do ?
 
Physics news on Phys.org
plot3 is the function you want, set the z component equal to the value you want.
 
not formed ,,,hmmmm
the case is,,, I have equation of two variables,,
simply
x=linspace(0,1)
y=x^2
plot(x,y,'b')
now I want to convert this parabolic in 3D
x=linspace(0,1)
z=-1:0.1:1;
y=x^2
plot3(x,y,z)
but not working it gives
? Error using ==> mpower
Matrix must be square.
 
I tried what you said for different example work but I need graph as in attachment,
 

Attachments

Last edited:

Similar threads

Replies
4
Views
4K
Replies
2
Views
3K
Replies
4
Views
2K
Replies
1
Views
2K
Replies
1
Views
3K
Replies
2
Views
2K
Back
Top