This document discusses how to plot 1D, 2D, and 3D graphs in MATLAB. It provides examples of basic 1D plots using the plot command. For 2D plots, it demonstrates plotting multiple functions on the same graph and customizing axes labels and titles. Examples are given for basic 3D plots using plot3, including plotting a helix, points as markers without lines, surfaces, and mesh plots. The document concludes with references for further reading.
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)
90 views18 pages
MATLAB 1D, 2D, 3D Plotting Guide
This document discusses how to plot 1D, 2D, and 3D graphs in MATLAB. It provides examples of basic 1D plots using the plot command. For 2D plots, it demonstrates plotting multiple functions on the same graph and customizing axes labels and titles. Examples are given for basic 3D plots using plot3, including plotting a helix, points as markers without lines, surfaces, and mesh plots. The document concludes with references for further reading.
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}
Student name: Aram Nasih Muhammad
ljSÖDFIWO09IHGFWAEEGESGSDG Class : 3rd stage Course title: programing matlab Department : Chemical engineering
Faculty of engineering Soran university Academic year 2019-2020
1|Page 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 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.
2|Page Plot-manipulations
Basic 1-D plot :
3|Page A = [1.0,4.0,16.0,32.0]; x = [1,2,3,4]; clf; % Clear the plot. plot(x,A);
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');
4|Page A = [1.0,4.0,16.0,32.0]; 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 :
5|Page 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)
Output:
For example :
6|Page > 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
9|Page t = 0:pi/50:10*pi; st = sin(t); ct = cos(t); plot3(st,ct,t)
output :
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')
10 | P a g e output :
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