(How To Plot 1-D, 2-D and 3-D in Matlab) : Department: Chemical Engineering
The document discusses how to plot 1D, 2D, and 3D graphs in MATLAB. It provides examples of basic 1D, 2D, and 3D plots using simple functions like sin and cos. It demonstrates how to customize plots by adding labels, titles, and grids. Multiple functions can be plotted on the same 2D graph. 3D plots include examples of surfaces, meshes, and scatter plots. The conclusion emphasizes that visualization helps with data analysis and MATLAB enables easy generation of graphs.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
84 views18 pages
(How To Plot 1-D, 2-D and 3-D in Matlab) : Department: Chemical Engineering
The document discusses how to plot 1D, 2D, and 3D graphs in MATLAB. It provides examples of basic 1D, 2D, and 3D plots using simple functions like sin and cos. It demonstrates how to customize plots by adding labels, titles, and grids. Multiple functions can be plotted on the same 2D graph. 3D plots include examples of surfaces, meshes, and scatter plots. The conclusion emphasizes that visualization helps with data analysis and MATLAB enables easy generation of graphs.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 18
{How to plot 1-D ,2-D and 3-D in matlab}
Department : Chemical engineering
Faculty of engineering Soran university Academic year 2019-2020
Introduction
MATLAB has an excellent set of graphic tools. Plotting a given data set or the results of computation is possible with very few commands. Creating plots of data sets and functions is very useful for engineers and scientists. You can use plots to present results for papers and
1|Page presentations or to visually search for approximate solutions to problems. You are highly encouraged to plot mathematical functions and results of analysis as often as possible. Trying to understand mathematical equations with graphics is an enjoyable and very efficient way of learning mathematics. Being able to plot mathematical functions and data freely is the most important step, and this section is written to assist you to do just that.
[-9iawufihawkg.na, XCJb vkns ,kxhv adivjc
Plot-manipulations
2|Page Basic 1-D plot :
A = [1.0,4.0,16.0,32.0]; x = [1,2,3,4]; clf; % Clear the plot. plot(x,A);
3|Page A = [1.0,4.0,16.0,32.0]; x = [1,2,3,4]; clf; plot(x,A); grid on; xlabel('Time [seconds]'); ylabel('Height [meters]'); title('Experiment 1 results');
A = [1.0,4.0,16.0,32.0];
4|Page x = [1,2,3,4]; clf; plot(x,A); % Label x-position labels % at 1, 2, 3, and 4. set(gca,'XTick',[1:4]); grid on; xlabel('Time [seconds]'); ylabel('Height [meters]'); title('Experiment 1 results');
Basic 2-D plot :
The basic command for producing a simple 2-D plot is plot(x values, y values, ‘style_color_marker’) .
For Example:
Let’s create 2D line plot for y=sin(x) where x ranges from 0 to 2*pi:
>x=0:pi/100:2*pi
>y=sin(x)
>plot(x,y) 5|Page Output:
For example :
> x=0:pi/100:2*pi;
y=sin(x);
%Create the graph with labeling x axis as ‘x-axis’, ‘y’ axis as
‘y-axis’
%with title 'Graph customization' and makes the grid for both the
t = 0:pi/50:10*pi; st = sin(t); ct = cos(t); plot3(st,ct,t)
output :
9|Page Plot Points as Markers Without Lines :
t = 0:pi/20:10*pi; xt = sin(t); yt = cos(t); plot3(xt,yt,t,'-o','Color','b','MarkerSize',10,'MarkerFaceColor','#D9FFFF')
output :
10 | P a g e Plot Surface : Create a 2-D grid with uniformly spaced x-coordinates and y-coordinates in the interval [-2,2]. x = -2:0.25:2; y = x; [X,Y] = meshgrid(x); F = X.*exp(-X.^2-Y.^2); surf(X,Y,F)
output:
11 | P a g e Basic 3D Surface Example using SURF xd=linspace(-1,1);
15 | P a g e xlabel('x'),ylabel('y'),zlabel('z') title('3D Example with different domains') hold on z2=x.^2./y; mesh(x,y,z2) hold off
Conclusion
2D plot in MATLAB enables a user to visualize the data which helps for further data processing. It helps to generate the graphs programmatically. Thus it makes the process of comparing data points, tracking changes in data over time, pattern in data distribution fast and easy. we can say that this sofware offers strong possibilities. The utilisation is pretty easy for simple problem. For advanced problem, it is more complex. Moreover, you can access to introduction course on internet. But for advanced functions, it is more complex for find books or article. Moreover, there is some books and user manual but there are paying and expensive. There is a lot of similarities with Matlab. The graphic interface on scilab is less advanced : it is 16 | P a g e a simple interface, less developed than Matlab. For example, computation on matrix have similar syntax. Nevertheless, some functions proposed in scilab are limited or complex for a beginner. For example, the matlab to scilab translator is not very efficient and require strong skills of matlab. Some functions such as graphics or data interfacing are complex at the beginning.
Reference : I. https://www.educba.com/2d-plots-in-matlab/ II. https://www.ludu.co/course/introduction-to-matlab/plotting III. https://electrosome.com/introduction-to-2d-plotting-in-matlab/
IV. https://ch.mathworks.com/help/matlab/ref/plot3.html
V. http://math.loyola.edu/~loberbro/matlab/html/Plot3Dsurfaces.html
17 | P a g e VI. http://hmf.enseeiht.fr/travaux/CD0102/travaux/optmfn/micp/reports/s17slie/index.htm
VII. http://computingforscientists.info/1D_Plotting