This document is an introduction to plotting with MATLAB. It discusses how to create basic 1D and 2D plots, present multiple functions on the same graph, and make basic 3D surface and volumetric plots. It also covers adding labels, titles, and adjusting plot properties. The document provides examples of plotting simple functions like sine and cosine waves to demonstrate MATLAB's plotting capabilities.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
55 views17 pages
Aram Nasih Muhammad Report
This document is an introduction to plotting with MATLAB. It discusses how to create basic 1D and 2D plots, present multiple functions on the same graph, and make basic 3D surface and volumetric plots. It also covers adding labels, titles, and adjusting plot properties. The document provides examples of plotting simple functions like sine and cosine waves to demonstrate MATLAB's plotting capabilities.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17
{Introduction to Plotting with Matlab}
Student name: Aram Nasih Muhammad
Class : 3rd stage
Course title: programing matlab
Department : Chemical engineering
Faculty of engineering
Soran university
Academic year 2019-2020
1|Page Contents Introduction ....................................................................................................................................................... 3 Plot-manipulations ............................................................................................................................................. 3 Basic 1-D plot :.................................................................................................................................................. 4 Basic 2-D plot :.................................................................................................................................................. 6 Presenting multiple functions on the same graph: ............................................................................................... 8 Basic 3-D plot :.................................................................................................................................................. 9 Plot Points as Markers Without Lines : ............................................................................................................ 10 Plot Surface : ................................................................................................................................................... 11 Basic 3D Surface Example using SURF ........................................................................................................... 12 Using MESH ................................................................................................................................................... 13 Adding axes labels, titles ................................................................................................................................. 14 Another 3D Surface Example .......................................................................................................................... 15 Conclusion ...................................................................................................................................................... 16
2|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.
Plot-manipulations
3|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);
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');
5|Page 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)
Output:
6|Page 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 axis %visible plot(x, y), xlabel('x-axis'), ylabel('y-axis'), title('Graph customisation'), grid on
7|Page Output:
Presenting multiple functions on the same graph:
MATLAB has extended features to plot multiple functions within one single graph.
Code: The code is written to represent the functions y1 and y2 in one single graph
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);
yd=linspace(0,2*pi);
[x,y]=meshgrid(xd,yd);
z=x.*cos(y);
surf(x,y,z)
output :
12 | P a g e Using MESH xd=linspace(-1,1);
yd=linspace(0,2*pi);
[x,y]=meshgrid(xd,yd);
z=x.*cos(y);
surf(x,y,z);
mesh(x,y,z)
output :
13 | P a g e Adding axes labels, titles xd=linspace(-1,1);
yd=linspace(0,2*pi);
[x,y]=meshgrid(xd,yd);
z=x.*cos(y);
surf(x,y,z);
mesh(x,y,z)
xlabel('x'),ylabel('y'),zlabel('z')
title('3D Plot Example')
output :
14 | P a g e Another 3D Surface Example
u=linspace(0.75,1.25,51);
v=linspace(-1.25,-0.75,51);
[x,y]=meshgrid(u,v);
z1=y.*exp(x.^2);
mesh(x,y,z1)
xlabel('x'),ylabel('y'),zlabel('z')
title('3D Example with different domains')
hold on
z2=x.^2./y;
mesh(x,y,z2)
hold off
15 | P a g e 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 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.