Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to MATLAB

Similar presentations


Presentation on theme: "Introduction to MATLAB"— Presentation transcript:

1 Introduction to MATLAB
EE-589 Introduction to Neural Networks

2 History of MATLAB Ancestral software to MATLAB
Fortran subroutines for solving linear (LINPACK) and eigenvalue (EISPACK) problems Developed primarily by Cleve Moler in the 1970’s

3 History of MATLAB, con’t: 2
The Mathworks, Inc. was created in 1984 The Mathworks is now responsible for development, sale, and support for MATLAB The Mathworks is located in Natick, MA The Mathworks is an employer that hires co-ops through our co-op program

4 MATLAB GUI Launch Pad / Toolbox Workspace Current Directory
Command History Command Window

5 Launch Pad / Toolbox Will not be covered
Launch Pad allows you to start help/demos Toolbox is for use with specialized packages (Signal Processing)

6 Workspace Allows access to data
Area of memory managed through the Command Window Shows Name, Size (in elements), Number of Bytes and Type of Variable

7 Current Directory MATLAB, like Windows or UNIX, has a current directory MATLAB functions can be called from any directory Your programs (to be discussed later) are only available if the current directory is the one that they exist in

8 Command History Allows access to the commands used during this session, and possibly previous sessions Clicking and dragging to the Command window allows you to re-execute previous commands

9 Command Window Probably the most important part of the GUI
Allows you to input the commands that will create variables, modify variables and even (later) execute scripts and functions you program yourself.

10 Save save – saves workspace variables on disk
save filename stores all workspace variables in the current directory in filename.mat save filename var1 var2 ... saves only the specified workspace variables in filename.mat. Use the * wildcard to save only those variables that match the specified pattern.

11 Clear clear removes items from workspace, freeing up system memory
Examples of syntax: clear clear name clear name1 name2 name3 ...

12 clc Not quite clear clc clears only the command window, and has no effect on variables in the workspace.

13 Load load - loads workspace variables from disk Examples of Syntax:
load filename load filename X Y Z

14 The presence or lack of a semi-colon after a MATLAB command does not generate an error of any kind
The presence of a semi-colon tells MATLAB to suppress the screen output of the command

15 The lack of a semi-colon will make MATLAB output the result of the command you entered
One of these options is not necessarily better than the other

16 Declaring a variable, con’t: 3
You may now use the simple integer or float that you used like a normal number (though internally it is treated like a 1 by 1 matrix) Possible operations: +, -, / Many functions (round(), ceil(), floor())

17 Declaring a variable, con’t: 4
You may also make a vector rather simply The syntax is to set a variable name equal to some numbers, which are surrounded by brackets and separated by either spaces or commas Ex. A = [ ]; Or A = [1,2,3,4,5];

18 Declaring a variable, con’t: 5
You may also declare a variable in a general fashion much more quickly Ex. A = 1:1:10 The first 1 would indicate the number to begin counting at The second 1 would be the increase each time And the count would end at 10

19 Declaring a variable, con’t: 6
Matrices are the primary variable type for MATLAB Matrices are declared similar to the declaration of a vector Begin with a variable name, and set it equal to a set of numbers, surrounded by brackets. Each number should be seperated by a comma or semi-colon

20 Declaring a variable, con’t: 7
The semi-colons in a matrix declaration indicate where the row would end Ex. A = [ 1,2;3,4] would create a matrix that looks like [ 1 2 3 4 ]

21 Everything is matrix

22 Matrix index

23 Manipulate matrices

24 Manipulate matrices

25

26 Script or function? Scripts are m-files containing MATLAB statements
Functions are like any other m-file, but they accept arguments It is always recommended to name function file the same as the function name

27 Try to code in matrix ways

28 Script m-files

29 mesh

30 x=[ -10:1:10]; y = [-10:4:10]; [x, y] = meshgrid(x,y); z = x.^2 + y.^2; mesh(x,y,z); title('Mesh Ornek 3'); ylabel('Y Ekseni'); xlabel('X Ekseni'); zlabel('Z Eksen');

31

32 Plotting Several types of plots available Plot Polar Bar Hist

33 Color options Color options: Example: plot(temp, ‘y’); Yellow - ‘y’
Magenta - ‘m’ Cyan - ‘c’ Red - ‘r’ Green - ‘g’ Blue - ‘b’ White - ‘w’ Black - ‘k’ Example: plot(temp, ‘y’);

34 Line options Line styles: - solid line (default) -- dashed line
: dotted line -. dash-dot line

35 Marker Options + - plus sign o - circle * - asterisk . - Point
x - cross s - square d - diamond ^ - upward pointing triangle v - downward pointing triangle > - right pointing triangle < - left pointing triangle p - five-pointed star (pentagram) h - six-pointed star (hexagram)

36 Plot() (from MATLAB help)
Linear 2-D plot Syntax: plot(Y) plot(X1,Y1,...) plot(X1,Y1,LineSpec,...) plot(...,'PropertyName',PropertyValue,...) h = plot(...)

37 Plot() con’t: 2 MATLAB defaults to plotting a blue line between points
Other options exist: Different color lines Different types of lines No line at all!

38 Example angle = linspace(0, 2*pi, 360); x = cos(angle); y = sin(angle); plot(x,y); % it draws a circle axis('equal'); ylabel('y'); xlabel('x'); title('Pretty Circle') ; grid on

39

40 Polar() Plot polar coordinates Syntax:
polar(theta,rho) polar(theta,rho,LineSpec) Theta – Angle counterclockwise from the 3 o’clock position Rho – Distance from the origin

41 Polar() con’t: 2 Line color, style and markings apply as they did in the example with Plot(). t = 0:.01:2*pi; polar(t,sin(2*t).*cos(2*t),'--r')

42 Bar() Creates a bar graph Syntax bar(Y) bar(x,Y) bar(...,width)
bar(...,'style') bar(...,LineSpec)

43 Bar example subplot(3,1,1), bar(rand(10,5),'stacked'), colormap(cool) subplot(3,1,2), bar(0:.25:1,rand(5),1) subplot(3,1,3),bar(rand(2,3),.75,'grouped')

44 Hist() Creates a histogram plot Syntax: n = hist(Y) n = hist(Y,x)
n = hist(Y,nbins) Example x = -4:0.1:4; y = randn(10000,1); hist(y,x)

45 Pie x=[ ]; pie(x) explode = zeros(size(x)); h = pie(x, explode); textObjs = findobj(h, 'Type', 'text'); oldStr = get(textObjs, {'String'}); val = get(textObjs, {'Extent'}); oldExt = cat(1, val{:}); Names = {'P1: '; 'P2: '; 'P3: '; 'P4: '}; newStr = strcat(Names, oldStr); set (textObjs, {'String'}, newStr)

46 Another satisfied MATLAB user!
End


Download ppt "Introduction to MATLAB"

Similar presentations


Ads by Google