






























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Lecture slides on modeling and simulation, focusing on the introduction to matlab and creating 2d plots. It covers creating vectors, plotting functions, and customizing plots with labels, text, and grids. It also introduces various plotting commands and multiple graphs.
Typology: Slides
1 / 38
This page cannot be seen from the preview
Don't miss anything!
Lecture: Introduction to Matlab
x = 0:pi/100:2pi; y = sin(x); plot(x,y,'LineWidth',3)*
Now label the axes and add a title. The characters \pi create the symbol. See text strings for more symbols: xlabel('x = 0:2\pi') ylabel('Sine of x') title('Plot of the Sine Function','FontSize',12)
For example, these statements use the colon operator to create a vector of x values ranging from 0 to 2, compute the sine of these values, and plot the result:
% prog2.m t = -1 : 0.01 : 1; f = 4.5cos(2pit - pi/6); plot(t,f 'LineWidth',3),title('Fig.2a'); axis([-1, 1, -6, 6]); xlabel('time, t'); ylabel('f(t)'); text(-0.6, 5,' f(t) = A cos(wt + phi)'); grid;*
Resulting graph
Resulting
figure
PLOT(X,Y) plots vector Y versus vector X. TITLE('text') adds text at the top of the current plot. XLABEL('text') adds text beside the X-axis on the current axis. YLABEL('text') adds text beside the Y-axis on the current axis. GRID, by itself, toggles the major grid lines of the current axes.
GTEXT('string') displays the graph window, puts up a cross-hair, and waits for a mouse button or keyboard key to be pressed. SUBPLOT(m,n,p), or SUBPLOT(mnp),
breaks the Figure window into an m-by-n matrix of small axes. STEM(Y) stemDiscrete sequence or "stem" plot. STEM(Y) plots the data sequence Y as stems from the x axis terminated with circles for the data value. SEMILOGX(...) is the same as PLOT(...), except a logarithmic (base 10) scale is used for the X-axis. SEMILOGY(...) is the same as PLOT(...), except a logarithmic (base 10) scale is used for the Y-axis..
Results
Colors Line Styles y yellow. point M magenta o circle C cyan x x-mark R red + plus G green - solid B blue * star W white : dotted K black -. Dashdot -- dashed More mark types are; square(s), diamond(d), up-triangle(v), down- triangle(^), left-triangle(<), right-triangle(>), pentagram(p), hexagram(h) See also help plot for more line and mark color.
2 dimensions line plots (x vs. y), filled plots, bar charts, pie charts, parametric plots, polar plots, contour plots, density plots, log axis plots, surface plots, parametric plots in 3 dimensions and spherical plots.
To preview some of these capabilities and others as well, enter the command demos.
MATLAB supports many types of graph and surface plots:
meshgrid: generate X and Y arrays for 3-D plots mesh: draws a wireframe mesh surf: plot a 3-D shaded surface colorbar: add a color bar tool patch: creating patch graphics objects hidden: remove hidden lines from mesh plot
0
10
0
10
-0.
0
Z = sin(R)./R; mesh(X,Y,Z) 1