Professional Documents
Culture Documents
Computer Applications in Engineering Design: M Files & Visualizing Data in Matlab
Computer Applications in Engineering Design: M Files & Visualizing Data in Matlab
Engineering Design
LECTURE 2
M FILES & VISUALIZING DATA IN MATLAB
asim.raheel@uettaxila.edu.pk
➢Scalar/Vector/Matrix
➢MATLAB basic commands
➢Use the MATLAB Editor or another text editor to create a file containing the same statements
you would type at the MATLAB command line
Note:
➢Function name should be same as the name of script
Note:
➢Name of the script should be add.m
➢Otherwise use:
Create a function that finds the solution for x based on different input values for a, b and
c.
4.5
➢x=[0 1 2 3 4] 4
➢Plot(x,y) 3.5
2.5
1.5
0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4
➢x=[0 1 2 3 4] 4
➢Plot(x,y) 3.5
3
➢Title(‘My figure’)
Amplitude
2.5
➢Xlabel(‘abc’) 2
➢Ylabel(‘Amplitude’) 1.5
0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4
abc
0.8
➢Plot 0.6
0.4
➢>> y=sin(t);
0 1
-0.2 0.9
-0.6 0.7
➢Stem -0.8 0.6
➢>>t=0:.01:2; -1
0 1 2 3 4 5 6 7 8 9 10
0.5
0.4
0.2
➢>> stem(t,y) 0.1
0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
4.5
➢Bar Graph 4
4
2
➢>> bar(x,y) 1.5
0.5
➢>> barh(x,y)
0
➢>> bar3(x,y) 0
3
1
➢Horizontal 3D Bar Graph 2
2
3
1
➢>> y=[1 3 5 3 0]; 4
➢Pie Chart
➢>>x=[1 2 3 4] 20% 40%
➢>>pie(x) A
OR
B D
➢>>x=[1 2 3 4]
30%
➢>>pie(x,{‘A’,’B’,’C’,’D’})
➢>>x=[1 2 3 4]
➢>>Explode=[0 1 0 0] B D
subplot(2,2,2), stem(x,y), 3 3
2 2
subplot(2,2,3), bar(x,y), 1 1
subplot(2,2,4), barh(x,y) 0
0 1 2 3 4
0
0 1 2 3 4
4
4
3 3
2
2 1
0
1
0
0 1 2 3 4 0 2 4 6