Matlab workshop

26
Mohamed Abd Elhay

Transcript of Matlab workshop

Page 1: Matlab workshop

Mohamed Abd Elhay

Page 2: Matlab workshop

Mohamed Abd Elahy

Embedded SW Engineer

Tel./010 9 15 77 828

Email/ [email protected]

Page 3: Matlab workshop
Page 4: Matlab workshop

o MATLAB Desktop.

o Simulink

o GUI

Page 5: Matlab workshop

MATLAB stands for matrix laboratory.

o High-performance language for

technical computing.

o Integrates computation,

visualization, and programming in

an easy-to-use environment where

problems and solutions are

expressed in familiar mathematical

notation.

Page 6: Matlab workshop

o Math and computation

o Algorithm development

o Data acquisition

o Modeling, simulation, and prototyping

o Data analysis, exploration, and visualization

o Scientific and engineering graphics

o Application development, including

graphical user interface building

The MATLAB Application:

Page 7: Matlab workshop

The MATLAB system have five main parts:

1. Development Environment.

2. The MATLAB Mathematical Function Library.

3. The MATLAB Language.

4. Graphics.

5. The MATLAB Application Program Interface (API).

Code Generation

Blocksets

PC-based real-time systems

Stateflow Stateflow Stateflow Toolboxes

DAQ cards Instruments

Databases and files Financial Datafeeds

Desktop Applications Automated Reports

Page 8: Matlab workshop

Variable

browser

Command

window

Command history

MATLAB Disktop

Page 9: Matlab workshop

Command window

• save filename % save data from workspace to a file

• load filename % loads data from file to a workspace

• who % list variables exist in the workspace

• whos % list variables in details

• clear % clear data stored in the workspace

• clc % clears the command window

• ctrl+c % To abort a command

• exit or quit % to quit MATLAB

Page 10: Matlab workshop

Variables

• Variable name must start with letter.

• It is case sensitive.

• Hyphen o isvarname X_001 % Check possibility

o isvarname if

• Max length o namelengthmax % depends on MATLAB version

• Variable can’t have the same name of keyword o iskeyword % list all MATLAB keywords

Page 11: Matlab workshop

Variables

o x= [ 2 4 5 6 77 65] % vector

o x= [ 2,4,5,6,77,65] % same vector

o y= [3 7 5;5 6 3] % matrix 2x3

o startP= 1;endP= 10; number_of_points= 100;

x= linspace (startP, endP, number_of_points)

o step= 0.1;

x= startP : step : endP;

Page 12: Matlab workshop

Vectors & matrix operations

min(x); max(x) % minimum; maximum elements

sum(x); prod(x) % summation ; multiplication of all elements

length(x); % return the length of the vector

size(x) % return no. of row and no. of columns

anyVector(end) % return the last element in the vector

find(x==value) % get the indices

[v,e]=eig(x) % eign vectors and eign values

fliplr(x) % flip the vector left-right

Z=X*Y % vectorial multiplication

y= sin(x).*exp(-0.3*x) % element by element multiplication

Page 13: Matlab workshop

Plot

t=0:0.25:7;

y = sin(t);

plot(t,y) ;

xlabel('x axis');

ylabel('y axis');

title('Heading');

grid on;

gtext('text');

Page 14: Matlab workshop

IF Condition

a= input( ‘A‘ ) if rem(a,2) ==0 msgbox(‘a is even’); else msgbox(‘a is odd’); end

A='bye'; switch A

case 'hi' msgbox('he says hi')

case 'bye' msgbox('he says bye')

otherwise msgbox('nothing')

end

Switch case

Page 15: Matlab workshop

IF Condition

a= input( ‘A‘ ) if rem(a,2) ==0 msgbox(‘a is even’); else msgbox(‘a is odd’); end

A='bye'; switch A

case 'hi' msgbox('he says hi')

case 'bye' msgbox('he says bye')

otherwise msgbox('nothing')

end

Switch case

Page 16: Matlab workshop

for n = 1:32 r(n) = n;

end

For Loop

x = 1;

while (x^2<10) %(Condition)

y=x^2;

plot(x,y,’or’); hold on

x = x+1;

end

While Loop

Page 17: Matlab workshop

Statistics Statistics Toolbox o Contains about 250 functions and GUI’s for:

generating random numbers, probability

distributions, hypothesis Testing, statistical

plots and covers basic statistical functionality

Signal Processing Toolbox o An environment for signal analysis

waveform generation, statistical signal

processing, and spectral analysis

o Useful for designing filters in conjunction with

the image

processing toolbox

Signal Processing

Page 18: Matlab workshop

Neural Network Toolbox o GUI for creating, training, and simulating

neural networks.

o It has support for the most commonly used

supervised

Optimization Toolbox o Includes standard algorithms for optimization

o Including minimax, goal attainment, and semi-

infinite minimization problems

Neural Networks

Optimization

Page 19: Matlab workshop

Curve Fitting Toolbox o Allows you to develop custom linear and

nonlinear models in a graphical user interface.

o Calculates fits, residuals, confidence intervals,

first derivative and integral of the fit.

Another Tool boxes : o Communications Toolbox

o Control System Toolbox

o Data Acquisition Toolbox

o Database Toolbox

o Image Processing Toolbox

o Filter Design Toolbox

o Financial Toolbox

o Fixed-Point Toolbox

o Fuzzy Logic Toolbox

Page 20: Matlab workshop

20/14

o Simulink is a graphical, “drag and drop” environment for building

simple and complex signal and system dynamic simulations.

o It allows users to concentrate on the structure of the problem, rather

than having to worry (too much) about a programming language.

o The parameters of each signal and system block is configured by the

user (right click on block)

o Signals and systems are simulated over a particular time.

vs, v

c

t

Page 21: Matlab workshop

o .fig

MATLAB Figure

o .m

MATLAB function, script, or class

o .mat

MATLAB binary file for storing variables

o .mex MATLAB executable (platform specific, e.g. ".mexmac" for the Mac, ".mexglx" for Linux)

Page 22: Matlab workshop

o GUIDE : stores GUIs in two files, which are generated the

first time you save or run the GUI:

.fig file :

Contains a complete description of the GUI

figure layout and the components of the GUI,

Changes to this file are made in the Layout

Editor.

.m file :

Contains the code that controls the GUI, You

can program the callbacks in this file using

the M-file Editor.

Page 23: Matlab workshop

Excel / COM

File I/O

C/C++

Java

Perl

Page 24: Matlab workshop

Excel COM

Page 25: Matlab workshop

a =imread('cameraman.tif'); imshow(a); pixval on;

a =wavread('test.wav');

wavplay(a,44100);

Plot(a);

a=aviread('movie.avi'); movie(a);

oImage oVideo oAudio

Page 26: Matlab workshop