Two Days workshop on MATLAB
-
Upload
bhavesh-shah -
Category
Education
-
view
1.754 -
download
4
Transcript of Two Days workshop on MATLAB
![Page 1: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/1.jpg)
Two Days workshop on
MATLAB(MATrix LABoratory)
[27-28 Sept, 2012]
Presented By:Bhavesh Shah
Asst. Prof., GF’s GCOE, Jalgaon
![Page 2: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/2.jpg)
Outline: What is MATLAB? MATLAB Screen Variables, array, matrix, indexing Operators (Arithmetic, relational, logical) Display Facilities Flow Control Writing User Defined Functions Design Neural Network(NN) Graphical User Interface (GUI) Image Processing Toolbox Advantages and Disadvantages of MATLAB Conclusion
27-28 Sept,2012 2MATLAB workshop under CSI
Student Chapter
![Page 3: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/3.jpg)
What is MATLAB?The MATLAB is high-performance language for technical computing integrates computation, visualization, and programming in an easy-to-use environment where problems and solutions are expressed in familiar mathematical notation.
Where MATLAB is used
Math and computation
Algorithm development
Data acquisition
Modelling, simulation, and prototyping
Data analysis, exploration, and visualization
Scientific and engineering graphics
Application development, including graphical user interface building
27-28 Sept,2012 3MATLAB workshop under CSI
Student Chapter
![Page 4: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/4.jpg)
Toolboxes provided By MATLAB1. Aerospace Simulation
2. Neural Network
3. Parallel Computing
4. Image Acquisition
5. Image processing
6. Genetic Algorithm
7. Fuzzy Logic
8. Database processing
9. Video and Image processing
10. Control System
11. Signal Processing
12. Statistics
13. Financial Toolbox
14. Curve fitting
27-28 Sept,2012 4MATLAB workshop under CSI
Student Chapter
![Page 5: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/5.jpg)
Toolboxes provided By MATLAB1. Aerospace Simulation
2. Neural Network
3. Parallel Computing
4. Image Acquisition
5. Image processing
6. Genetic Algorithm
7. Fuzzy Logic
8. Database processing
9. Video and Image processing
10. Control System
11. Signal Processing
12. Statistics
13. Financial Toolbox
14. Curve fitting
27-28 Sept,2012 5MATLAB workshop under CSI
Student Chapter
![Page 6: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/6.jpg)
MATLAB Screen Command Window
type commands
Current Directory View folders and m-files
Workspace View program variables Double click on a variable
to see it in the Array Editor
Command History view past commands save a whole session
using diary
27-28 Sept,2012 6MATLAB workshop under CSI
Student Chapter
![Page 7: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/7.jpg)
Structure of MATLAB
27-28 Sept,2012 7MATLAB workshop under CSI
Student Chapter
![Page 8: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/8.jpg)
Comment used in MATLAB “%” is the neglect sign for MATLAB (equivalent of
“//” in C). Anything after it on the same line is neglected by MATLAB compiler.
Sometimes slowing down the execution is done deliberately for observation purposes. You can use the command “pause” for this purpose
>>pause %wait until any key>>pause(3) %wait 3 seconds
27-28 Sept,2012 8MATLAB workshop under CSI
Student Chapter
![Page 9: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/9.jpg)
Useful Commands
The two commands used most by Matlab
users are
>>help functionname
>>lookfor keyword
27-28 Sept,2012 9MATLAB workshop under CSI
Student Chapter
![Page 10: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/10.jpg)
Variables No need for types. i.e.,
All variables are created with double precision unless specified and they are matrices.
After these statements, the variables are 1x1 matrices with double precision.
int a;double b;float c;
>>x=5;>>x1=2;
27-28 Sept,2012 10MATLAB workshop under CSI
Student Chapter
![Page 11: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/11.jpg)
Variables(cont…)
Use meaningful names for variables MATLAB variable names
– must begin with a letter
– can contain any combination of letters, numbers and underscore (_)
– must be unique in the first 31 characters MATLAB is case sensitive: “name”, “Name” and “NAME”
are considered different variables. Never use a variable with the same name as a MATLAB
command. Naming convention: use lowercase letters
27-28 Sept,2012 11MATLAB workshop under CSI
Student Chapter
![Page 12: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/12.jpg)
Variable(cont…)
Initialization using shortcut statements
– colon operator “first:increment:last”
>> x = 1:2:10
x =1 3 5 7 9
>> y = 0:0.1:0.5
y = 0 0.1 0.2 0.3 0.4 0.5
27-28 Sept,2012 12MATLAB workshop under CSI
Student Chapter
![Page 13: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/13.jpg)
Variable(cont…)
27-28 Sept,2012 13MATLAB workshop under CSI
Student Chapter
![Page 14: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/14.jpg)
Array
27-28 Sept,2012 14MATLAB workshop under CSI
Student Chapter
![Page 15: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/15.jpg)
Array, Matrix a vector x = [1 2 5 1]
x = 1 2 5 1
a matrix x = [1 2 3; 5 1 4; 3 2 -1]
x = 1 2 3 5 1 4 3 2 -1
transpose y = x’ y = 1
2 5
1
27-28 Sept,2012 15MATLAB workshop under CSI
Student Chapter
![Page 16: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/16.jpg)
Long Array, Matrix
t =1:10
t = 1 2 3 4 5 6 7 8 9 10 k =2:-0.5:-1
k = 2 1.5 1 0.5 0 -0.5 -1
B = [1:4; 5:8]
= 1 2 3 4 5 6 7 8
27-28 Sept,2012 16MATLAB workshop under CSI
Student Chapter
![Page 17: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/17.jpg)
Built-in Variables
pi: p value up to 15 significant digits i, j: sqrt(-1) Inf: infinity (such as division by 0) NaN: Not-a-Number (such as division of zero by zero). clock: current date and time as a vector date: current date as a string (e.g. 16-Feb-2004) eps: epsilon ans: default variable for answers tic…toc
27-28 Sept,2012 17MATLAB workshop under CSI
Student Chapter
![Page 18: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/18.jpg)
Built-in Math function
abs, sign log, log10, log2 exp sqrt sin, cos, tan max, min round, floor, ceil, fix mod
27-28 Sept,2012 18MATLAB workshop under CSI
Student Chapter
![Page 19: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/19.jpg)
Built in Functions
sort sortrows mod(num,2)
27-28 Sept,2012 19MATLAB workshop under CSI
Student Chapter
![Page 20: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/20.jpg)
Built in function related to String
27-28 Sept,2012 20MATLAB workshop under CSI
Student Chapter
![Page 21: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/21.jpg)
27-28 Sept,2012 21MATLAB workshop under CSI
Student Chapter
![Page 22: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/22.jpg)
Limit and Integration
27-28 Sept,2012 22MATLAB workshop under CSI
Student Chapter
![Page 23: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/23.jpg)
Differentiation
27-28 Sept,2012 23MATLAB workshop under CSI
Student Chapter
![Page 24: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/24.jpg)
Solving Equations
>> solve('cos(2*x)+sin(x)=1')
27-28 Sept,2012 24MATLAB workshop under CSI
Student Chapter
![Page 25: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/25.jpg)
Some useful Command
who: show your workspace whos: show your workspace with details memory: show memory status clc: clear command window clear: clear workspace variable cntl+d: forcefully quit diary: to maintain a log
27-28 Sept,2012 25MATLAB workshop under CSI
Student Chapter
![Page 26: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/26.jpg)
Initializing with Built-in Functions zeros(n) zeros(n,m) zeros(size(arr)) ones(n) ones(n,m) ones(size(arr)) eye(n) eye(n,m) length(arr) size(arr)
27-28 Sept,2012 26MATLAB workshop under CSI
Student Chapter
![Page 27: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/27.jpg)
Generating Vectors from functions zeros(M,N) MxN matrix of zeros
ones(M,N) MxN matrix of ones
rand(M,N) MxN matrix of uniformly distributed
random
numbers on (0,1)
x = zeros(1,3)x =
0 0 0
x = ones(1,3)x =
1 1 1
x = rand(1,3)x = 0.9501 0.2311 0.6068
27-28 Sept,2012 27MATLAB workshop under CSI
Student Chapter
![Page 28: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/28.jpg)
Matrix Index The matrix indices begin from 1 (not 0 (as in C)) The matrix indices must be positive integer
Given:
A(-2), A(0)
Error: ??? Subscript indices must either be real positive integers or logicals.
A(4,2)Error: ??? Index exceeds matrix dimensions.
27-28 Sept,2012 28MATLAB workshop under CSI
Student Chapter
![Page 29: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/29.jpg)
Concatenation of Matrices
x = [1 2], y = [4 5], z=[ 0 0]
A = [ x y]
1 2 4 5
B = [x ; y]
1 2 4 5
C = [x y ;z] Error:??? Error using ==> vertcat CAT arguments dimensions are not consistent.
27-28 Sept,2012 29MATLAB workshop under CSI
Student Chapter
![Page 30: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/30.jpg)
Operators (arithmetic)
+ addition
- subtraction
* multiplication
/ division
^ power
‘ transpose
27-28 Sept,2012 30MATLAB workshop under CSI
Student Chapter
![Page 31: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/31.jpg)
Matrices Operations
Given A and B:
Addition Subtraction Product Transpose
27-28 Sept,2012 31MATLAB workshop under CSI
Student Chapter
![Page 32: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/32.jpg)
Operators (Element by Element)
.* : element-by-element multiplication
./ : element-by-element division
.^ : element-by-element power
27-28 Sept,2012 32MATLAB workshop under CSI
Student Chapter
![Page 33: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/33.jpg)
The use of “.” – “Element” Operation
K= x^2Error: ??? Error using ==> mpower Matrix must be square.B=x*yError:??? Error using ==> mtimes Inner matrix dimensions must agree.
A = [1 2 3; 5 1 4; 3 2 1] A = 1 2 3 5 1 4 3 2 -1
y = A(3 ,:)
y= 3 4 -1
b = x .* y
b= 3 8 -3
c = x . / y
c= 0.33 0.5 -3
d = x .^2
d= 1 4 9
x = A(1,:)
x= 1 2 3
27-28 Sept,2012 33MATLAB workshop under CSI
Student Chapter
![Page 34: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/34.jpg)
Matrix Operation(cont…)
transpose(‘) tril: lower triangular matrix triu: upper triangular matrix rank: show rank of matrix det: determinant of matrix diag: returns principle diagonal inv: inverse of the matrix eig: eign value(matrix must be
square matrix)
27-28 Sept,2012 34MATLAB workshop under CSI
Student Chapter
![Page 35: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/35.jpg)
27-28 Sept,2012 35MATLAB workshop under CSI
Student Chapter
![Page 36: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/36.jpg)
Displaying Data/Text
27-28 Sept,2012 36MATLAB workshop under CSI
Student Chapter
![Page 37: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/37.jpg)
Displaying Data/Text(cont…)
27-28 Sept,2012 37MATLAB workshop under CSI
Student Chapter
![Page 38: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/38.jpg)
Displaying Data/Text(cont…)
27-28 Sept,2012 38MATLAB workshop under CSI
Student Chapter
![Page 39: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/39.jpg)
Import/Export Data from Command
27-28 Sept,2012 39MATLAB workshop under CSI
Student Chapter
![Page 40: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/40.jpg)
Operators (relational, logical)
== Equal to ~= Not equal to < Strictly smaller > Strictly greater <= Smaller than or equal to >= Greater than equal to & And operator | Or operator
27-28 Sept,2012 40MATLAB workshop under CSI
Student Chapter
![Page 41: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/41.jpg)
Flow Control
if for while break continue switch and case
27-28 Sept,2012 41MATLAB workshop under CSI
Student Chapter
![Page 42: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/42.jpg)
Control Structures
If Statement Syntax
if (Condition_1)MATLAB Commands
elseif (Condition_2) MATLAB Commands
elseif (Condition_3) MATLAB Commands
else MATLAB Commands
end
Some Dummy Examples
if ((a>3) & (b==5)) Some Matlab Commands;end
if (a<3) Some Matlab Commands;elseif (b~=5) Some Matlab Commands;end
if (a<3) Some Matlab Commands;else Some Matlab Commands;end
27-28 Sept,2012 42MATLAB workshop under CSI
Student Chapter
![Page 43: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/43.jpg)
Control Structures
For loop syntaxfor i=start: Last index
MATLAB Commands
end
Some Dummy Examples
for i=1:100 Some Matlab Commands;end
for j=1:3:200 Some Matlab Commands;end
for m=13:-0.2:-21 Some Matlab Commands;end
for k=[0.1 0.3 -13 12 7 -9.3] Some Matlab Commands;end
27-28 Sept,2012 43MATLAB workshop under CSI
Student Chapter
![Page 44: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/44.jpg)
Control Structures
While Loop Syntax
while (condition)
MATLAB Commands
end
Dummy Example
while ((a>3) & (b==5)) Some Matlab Commands;end
% while loop i=1;while(i<10) disp(i); i=i+1;end
27-28 Sept,2012 44MATLAB workshop under CSI
Student Chapter
![Page 45: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/45.jpg)
Use of M-File
Click to create a new M-File
• Extension “.m” • A text file containing script or function or program to run
27-28 Sept,2012 45MATLAB workshop under CSI
Student Chapter
![Page 46: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/46.jpg)
Switch and case
27-28 Sept,2012 46MATLAB workshop under CSI
Student Chapter
![Page 47: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/47.jpg)
Continue statement
27-28 Sept,2012 47MATLAB workshop under CSI
Student Chapter
![Page 48: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/48.jpg)
Break statement
27-28 Sept,2012 48MATLAB workshop under CSI
Student Chapter
![Page 49: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/49.jpg)
Use of M-File
If you include “;” at the end of each statement,result will not be shown immediately
Save file as Denem430.m
27-28 Sept,2012 49MATLAB workshop under CSI
Student Chapter
![Page 50: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/50.jpg)
Solution
>> A{1,1} = 'MATLAB ';
>> A{1,2} = 'SIMULINK ';
>> A = deblank(A)
A =
'MATLAB' 'SIMULINK'
27-28 Sept,2012 50MATLAB workshop under CSI
Student Chapter
![Page 51: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/51.jpg)
Writing User Defined Functions
Functions are m-files which can be executed by specifying some inputs and supply some desired outputs.
The code telling the MATLAB that an m-file is actually a function is
You should write this command at the beginning of the m-file and you should save the m-file with a file name same as the function name
function out1=functionname(inp1)function out1=functionname(inp1,inp2,inp3)function [out1,out2]=functionname(inp1,inp2)
27-28 Sept,2012 51MATLAB workshop under CSI
Student Chapter
![Page 52: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/52.jpg)
How to read a text file
fid = fopen('message.txt','r');
ice1= fread(fid);
s = char(ice1');
fclose(fid);
disp(s);
Ans hello
27-28 Sept,2012 52MATLAB workshop under CSI
Student Chapter
![Page 53: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/53.jpg)
How to write a text file
txt=[65 67 68 69];fid = fopen('output.txt','wb'); fwrite(fid,char(txt),'char');fclose(fid);
ANS =ACDE
27-28 Sept,2012 53MATLAB workshop under CSI
Student Chapter
![Page 54: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/54.jpg)
Writing User Defined Functions Examples
Write a function : out=squarer (A, ind) Which takes the square of the input matrix if the input
indicator is equal to 1 And takes the element by element square of the input
matrix if the input indicator is equal to 2
Same Name
27-28 Sept,2012 54MATLAB workshop under CSI
Student Chapter
![Page 55: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/55.jpg)
Basic Task: Plot the function sin(x) between 0≤x≤4π
Create an x-array of 100 samples between 0 and 4π.
Syntax: linspace(start, interval, end);
Calculate sin(.) of the x-array
Plot the y-array
>>x=linspace(0,4*pi,100);
>>y=sin(x);
>>plot(y)
27-28 Sept,2012 55MATLAB workshop under CSI
Student Chapter
![Page 56: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/56.jpg)
Plot the function e-x/3sin(x) between 0≤x≤4π Create an x-array of 100 samples between 0
and 4π.
Calculate sin(.) of the x-array
Calculate e-x/3 of the x-array
Multiply the arrays y and y1
>>x=linspace(0,4*pi,100);
>>y=sin(x);
>>y1=exp(-x/3);
>>y2=y*y1;
27-28 Sept,2012 56MATLAB workshop under CSI
Student Chapter
![Page 57: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/57.jpg)
Plot the function e-x/3sin(x) between 0≤x≤4π Multiply the arrays y and y1 correctly
Plot the y2-array
>>y2=y.*y1;
>>plot(y2)
0 10 20 30 40 50 60 70 80 90 100-0.3
-0.2
-0.1
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
27-28 Sept,2012 57MATLAB workshop under CSI
Student Chapter
![Page 58: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/58.jpg)
Display Facilities
plot(par1,par2)
Example:>>x=linspace(0,4*pi,100);>>y=sin(x);>>plot(y)>>plot(x,y)
0 10 20 30 40 50 60 70 80 90 100-0.3
-0.2
-0.1
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
27-28 Sept,2012 58MATLAB workshop under CSI
Student Chapter
![Page 59: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/59.jpg)
Neural Network
(NN)
27-28 Sept,2012 59MATLAB workshop under CSI
Student Chapter
![Page 60: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/60.jpg)
How to Design Neural Network1. Collect data
2. Create the network
3. Configure the network
4. Initialize the weights and biases
5. Train the network
6. Validate the network
7. Use the network
27-28 Sept,2012 60MATLAB workshop under CSI
Student Chapter
![Page 61: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/61.jpg)
Simple Neuron/1st layer Perceptron
bX1 wb=1
w1
y
w2
X2
E
27-28 Sept,2012 61MATLAB workshop under CSI
Student Chapter
![Page 62: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/62.jpg)
Transfer Function
27-28 Sept,2012 62MATLAB workshop under CSI
Student Chapter
![Page 63: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/63.jpg)
Vectors used in NN
27-28 Sept,2012 63MATLAB workshop under CSI
Student Chapter
![Page 64: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/64.jpg)
Neural Network Architecture
27-28 Sept,2012 64MATLAB workshop under CSI
Student Chapter
![Page 65: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/65.jpg)
27-28 Sept,2012 65MATLAB workshop under CSI
Student Chapter
![Page 66: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/66.jpg)
27-28 Sept,2012 66MATLAB workshop under CSI
Student Chapter
![Page 67: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/67.jpg)
Multilayer NN
27-28 Sept,2012 67MATLAB workshop under CSI
Student Chapter
![Page 68: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/68.jpg)
How to open Neural Network Tool>>nftool
27-28 Sept,2012 68MATLAB workshop under CSI
Student Chapter
![Page 69: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/69.jpg)
Graph Plot
27-28 Sept,2012 69MATLAB workshop under CSI
Student Chapter
![Page 70: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/70.jpg)
Display Facilities
title(.)
xlabel(.)
ylabel(.)
>>title(‘This is the sinus function’)
>>xlabel(‘x (secs)’)
>>ylabel(‘sin(x)’)0 10 20 30 40 50 60 70 80 90 100
-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1This is the sinus function
x (secs)
sin(
x)
27-28 Sept,2012 70MATLAB workshop under CSI
Student Chapter
![Page 71: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/71.jpg)
GUI(Graphical User Interface)
27-28 Sept,2012 71MATLAB workshop under CSI
Student Chapter
![Page 72: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/72.jpg)
GUIDE
GUIDE is Graphical User Interface Development Environment, provides a set of tools for creating graphical user interfaces (GUIs). These tools simplify the process of laying out and programming GUIs.
To open GUI :
>> guide
27-28 Sept,2012 72MATLAB workshop under CSI
Student Chapter
![Page 73: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/73.jpg)
DIALOG BOX
warndlg('hello'); helpdlg('hello'); errordlg('hello');
msgbox('hello');
27-28 Sept,2012 73MATLAB workshop under CSI
Student Chapter
![Page 74: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/74.jpg)
USER INTERFACE GET FILE[filename, pathname] = uigetfile('*.m', 'Pick an M-file'); if isequal(filename,0) | isequal(pathname,0) disp('User pressed cancel') else disp(['User selected ', fullfile(pathname, filename)]) end
27-28 Sept,2012 74MATLAB workshop under CSI
Student Chapter
![Page 75: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/75.jpg)
GUI…
27-28 Sept,2012 75MATLAB workshop under CSI
Student Chapter
![Page 76: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/76.jpg)
PUSH BUTTON
27-28 Sept,2012 76MATLAB workshop under CSI
Student Chapter
![Page 77: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/77.jpg)
TOGGLE BUTTON
27-28 Sept,2012 77MATLAB workshop under CSI
Student Chapter
![Page 78: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/78.jpg)
RADIO BUTTON
27-28 Sept,2012 78MATLAB workshop under CSI
Student Chapter
![Page 79: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/79.jpg)
CHECKBOX
27-28 Sept,2012 79MATLAB workshop under CSI
Student Chapter
![Page 80: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/80.jpg)
EDIT TEXT
27-28 Sept,2012 80MATLAB workshop under CSI
Student Chapter
![Page 81: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/81.jpg)
STATIC TEXT
27-28 Sept,2012 81MATLAB workshop under CSI
Student Chapter
![Page 82: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/82.jpg)
SLIDER
27-28 Sept,2012 82MATLAB workshop under CSI
Student Chapter
![Page 83: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/83.jpg)
FRAME
27-28 Sept,2012 83MATLAB workshop under CSI
Student Chapter
![Page 84: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/84.jpg)
LISTBOX
27-28 Sept,2012 84MATLAB workshop under CSI
Student Chapter
![Page 85: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/85.jpg)
POPUP MENU
27-28 Sept,2012 85MATLAB workshop under CSI
Student Chapter
![Page 86: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/86.jpg)
AXES
27-28 Sept,2012 86MATLAB workshop under CSI
Student Chapter
![Page 87: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/87.jpg)
ALIGN OBJECTS
27-28 Sept,2012 87MATLAB workshop under CSI
Student Chapter
![Page 88: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/88.jpg)
MENU EDITOR
27-28 Sept,2012 88MATLAB workshop under CSI
Student Chapter
![Page 89: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/89.jpg)
M FILE EDITOR
27-28 Sept,2012 89MATLAB workshop under CSI
Student Chapter
![Page 90: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/90.jpg)
PROPERTY INSPECTOR
27-28 Sept,2012 90MATLAB workshop under CSI
Student Chapter
![Page 91: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/91.jpg)
27-28 Sept,2012 91MATLAB workshop under CSI
Student Chapter
![Page 92: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/92.jpg)
RUN
27-28 Sept,2012 92MATLAB workshop under CSI
Student Chapter
![Page 93: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/93.jpg)
PUSH BUTTON
27-28 Sept,2012 93MATLAB workshop under CSI
Student Chapter
![Page 94: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/94.jpg)
WRITE THE CODE BELOW THE CALLBACK
a =imread('cameraman.tif');
imshow(a);
27-28 Sept,2012 94MATLAB workshop under CSI
Student Chapter
![Page 95: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/95.jpg)
RUN THE PROGRAM OR PRESS F5
27-28 Sept,2012 95MATLAB workshop under CSI
Student Chapter
![Page 96: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/96.jpg)
RIGHT CLICK PUSH BUTTON & GO FOR PROPERTY INSPECTOR
27-28 Sept,2012 96MATLAB workshop under CSI
Student Chapter
![Page 97: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/97.jpg)
CHOOSE AXES
27-28 Sept,2012 97MATLAB workshop under CSI
Student Chapter
![Page 98: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/98.jpg)
RIGHT CLICK AXES & GO FOR PROPERTY INSPECTOR
27-28 Sept,2012 98MATLAB workshop under CSI
Student Chapter
![Page 99: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/99.jpg)
CHANGE THE STRING AND TAG VALUE
27-28 Sept,2012 99MATLAB workshop under CSI
Student Chapter
![Page 100: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/100.jpg)
WRITE THE CODE BELOW THE CALLBACK
a =imread('cameraman.tif');
axes(handles.one);
imshow(a);
27-28 Sept,2012 100MATLAB workshop under CSI
Student Chapter
![Page 101: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/101.jpg)
RUN THE PROGRAM
27-28 Sept,2012 101MATLAB workshop under CSI
Student Chapter
![Page 102: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/102.jpg)
CODE
a =imread('cameraman.tif');
axes(handles.one);
imshow(a);
27-28 Sept,2012 102MATLAB workshop under CSI
Student Chapter
![Page 103: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/103.jpg)
TOGGLE BUTTON
27-28 Sept,2012 103MATLAB workshop under CSI
Student Chapter
![Page 104: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/104.jpg)
RIGHT CLICK TOGGLE & GO FOR PROPERTY INSPECTOR
27-28 Sept,2012 104MATLAB workshop under CSI
Student Chapter
![Page 105: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/105.jpg)
CHANGE THE STRING AND TAG VALUE
27-28 Sept,2012 105MATLAB workshop under CSI
Student Chapter
![Page 106: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/106.jpg)
RIGHT CLICK TOGGLE & GO FOR M FILE EDITOR
27-28 Sept,2012 106MATLAB workshop under CSI
Student Chapter
![Page 107: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/107.jpg)
WRITE THE CODE BELOW THE CALLBACK
a=get(hObject,'Value');
if a ==1 a =imread('cameraman.tif');
axes(handles.one);
imshow(a); else a =imread('greens.jpg');
axes(handles.one);
imshow(a); end
27-28 Sept,2012 107MATLAB workshop under CSI
Student Chapter
![Page 108: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/108.jpg)
RUN THE PROGRAM
27-28 Sept,2012 108MATLAB workshop under CSI
Student Chapter
![Page 109: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/109.jpg)
RIGHT CLICK CHECK BOX & GO FOR PROPERTY INSPECTOR
27-28 Sept,2012 109MATLAB workshop under CSI
Student Chapter
![Page 110: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/110.jpg)
CHANGE THE STRING AND TAG VALUE
27-28 Sept,2012 110MATLAB workshop under CSI
Student Chapter
![Page 111: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/111.jpg)
RIGHT CLICK CHECK BOX & GO FOR M FILE EDITOR
27-28 Sept,2012 111MATLAB workshop under CSI
Student Chapter
![Page 112: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/112.jpg)
WRITE THE CODE BELOW THE CALLBACK
27-28 Sept,2012 112MATLAB workshop under CSI
Student Chapter
![Page 113: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/113.jpg)
RUN THE PROGRAM
27-28 Sept,2012 113MATLAB workshop under CSI
Student Chapter
![Page 114: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/114.jpg)
Image Processing
27-28 Sept,2012 114MATLAB workshop under CSI
Student Chapter
![Page 115: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/115.jpg)
How to read an image
a =imread('cameraman.tif');imshow(a);pixval on;
a =imread('flowers.tif');imshow(a);pixval on;
27-28 Sept,2012 115MATLAB workshop under CSI
Student Chapter
![Page 116: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/116.jpg)
NOISE AND FILTER
I = imread('eight.tif'); J = imnoise(I,'salt & pepper',0.02); K = medfilt2(J); subplot(1,2,1);imshow(J)subplot(1,2,2);imshow(K)
27-28 Sept,2012 116MATLAB workshop under CSI
Student Chapter
![Page 117: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/117.jpg)
How to read an audio file
a =wavread('test.wav');wavplay(a,44100);Plot(a);
27-28 Sept,2012 117MATLAB workshop under CSI
Student Chapter
![Page 118: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/118.jpg)
How to read an video file
a=aviread('movie.avi');movie(a);
27-28 Sept,2012 118MATLAB workshop under CSI
Student Chapter
![Page 119: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/119.jpg)
Add two images
I = imread('rice.tif');
J = imread('cameraman.tif');
K = imadd(I,J,'uint16');
imshow(K,[])
I = imread('rice.tif'); J = imadd(I,Irice50); subplot(1,2,1), imshow(I) subplot(1,2,2), imshow(J)
27-28 Sept,2012 119MATLAB workshop under CSI
Student Chapter
![Page 120: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/120.jpg)
Subtract two images
I = imread('rice.tif');
Iq = imsubtract(I,Irice50);
subplot(1,2,1), imshow(I)
subplot(1,2,2), imshow(Iq)
27-28 Sept,2012 120MATLAB workshop under CSI
Student Chapter
![Page 121: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/121.jpg)
Convert image to gray and binaryclc;clear;close alla= imread('flowers.tif');subplot(2,2,1);imshow(a);subplot(2,2,2);b=imresize(a,[256 256]);imshow(b);subplot(2,2,3);c=rgb2gray(b);imshow(c);subplot(2,2,4);d=im2bw(c);imshow(d);
27-28 Sept,2012 121MATLAB workshop under CSI
Student Chapter
![Page 122: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/122.jpg)
RGB componenta=imread('flowers.tif');subplot(2,2,1);imshow(a);R=a;G=a;B=a;R(:,:,2:3)=0;subplot(2,2,2);imshow(R);G(:,:,1)=0;G(:,:,3)=0;subplot(2,2,3);imshow(G);B(:,:,1)=0;B(:,:,2)=0;subplot(2,2,4);imshow(B);
27-28 Sept,2012 122MATLAB workshop under CSI
Student Chapter
![Page 123: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/123.jpg)
Convert Image into One dimensional
a = imread('cameraman.tif');
[r c]=size(a);
Len=r*c;
b=reshape(a,[1 Len]);
27-28 Sept,2012 123MATLAB workshop under CSI
Student Chapter
![Page 124: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/124.jpg)
Counting the Number of Objects in an Imageclc;
clear;
close all;
InputImage=imread('eight.tif');
subplot(2,2,1);
imshow(InputImage);title('InputImage');
BinaryImage=im2bw(InputImage);
subplot(2,2,2);
imshow(BinaryImage);
ComplementImage=imcomplement(BinaryImage);
subplot(2,2,3);
imshow(ComplementImage);
HolesClearedImage = imfill(ComplementImage,'holes');
subplot(2,2,4);
imshow(HolesClearedImage);title('HolesClearedImage');
[L,Num] = bwlabel(HolesClearedImage)
for i=1:3
figure;
imshow(L==i);
pause(2)
end
27-28 Sept,2012 124MATLAB workshop under CSI
Student Chapter
![Page 125: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/125.jpg)
Advantages and Disadvantages of MATLAB Advantages
Ease of use Platform independence Predefined functions Plotting
Disadvantages Can be slow Expensive
27-28 Sept,2012 125MATLAB workshop under CSI
Student Chapter
![Page 126: Two Days workshop on MATLAB](https://reader037.fdocuments.us/reader037/viewer/2022103001/558910fad8b42acf788b472c/html5/thumbnails/126.jpg)
Thank You…
27-28 Sept,2012 126MATLAB workshop under CSI
Student Chapter