SlideShare uma empresa Scribd logo
1 de 126
Baixar para ler offline
Two Days workshop
         on
    MATLAB
  (MATrix LABoratory)
        [27-28 Sept, 2012]


             Presented By:
              Bhavesh Shah
    Asst. Prof., GF’s GCOE, Jalgaon
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

                       MATLAB workshop under CSI Student
27-28 Sept,2012                   Chapter                  2
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


                                       MATLAB workshop under CSI Student
 27-28 Sept,2012                                  Chapter                                 3
Toolboxes provided By MATLAB
1.     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
                            MATLAB workshop under CSI Student
27-28 Sept,2012                        Chapter                  4
Toolboxes provided By MATLAB
1.     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
                            MATLAB workshop under CSI Student
27-28 Sept,2012                        Chapter                  5
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


                                      MATLAB workshop under CSI Student
     27-28 Sept,2012                             Chapter                  6
Structure of MATLAB




                      MATLAB workshop under CSI Student
27-28 Sept,2012                  Chapter                  7
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



                             MATLAB workshop under CSI Student
27-28 Sept,2012                         Chapter                  8
Useful Commands

          The two commands used most by Matlab
           users are
             >>help functionname



             >>lookfor keyword




                          MATLAB workshop under CSI Student
27-28 Sept,2012                      Chapter                  9
Variables
      No need for types. i.e.,

                  int a;
                  double b;
                  float c;

      All variables are created with double precision unless
       specified and they are matrices.

                 >>x=5;
                 >>x1=2;


      After these statements, the variables are 1x1 matrices
       with double precision.
                              MATLAB workshop under CSI Student
    27-28 Sept,2012                      Chapter                  10
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
                        MATLAB workshop under CSI Student
27-28 Sept,2012                    Chapter                        11
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



                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  12
Variable(cont…)




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  13
Array




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  14
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



                                       MATLAB workshop under CSI Student
27-28 Sept,2012                                   Chapter                  15
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

                                   MATLAB workshop under CSI Student
27-28 Sept,2012                               Chapter                           16
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


                       MATLAB workshop under CSI Student
27-28 Sept,2012                   Chapter                    17
Built-in Math function

    abs, sign
    log, log10, log2
    exp
    sqrt
    sin, cos, tan
    max, min
    round, floor, ceil, fix
    mod

                       MATLAB workshop under CSI Student
27-28 Sept,2012                   Chapter                  18
Built in Functions

    sort
     sortrows
     mod(num,2)




                   MATLAB workshop under CSI Student
27-28 Sept,2012               Chapter                  19
Built in function related to String




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  20
MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  21
Limit and Integration




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  22
Differentiation




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  23
Solving Equations

>> solve('cos(2*x)+sin(x)=1')




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  24
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


                     MATLAB workshop under CSI Student
27-28 Sept,2012                 Chapter                  25
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)
                        MATLAB workshop under CSI Student
27-28 Sept,2012                    Chapter                  26
Generating Vectors from functions
   zeros(M,N) MxN matrix of zeros                 x = zeros(1,3)
                                                   x =
                                                     0     0      0

   ones(M,N)         MxN matrix of ones
                                                   x = ones(1,3)
                                                   x =
                                                     1     1     1
   rand(M,N)         MxN matrix of uniformly
                      distributed random      x = rand(1,3)
                      numbers on (0,1)        x =
                                                      0.9501        0.2311 0.6068

                                MATLAB workshop under CSI Student
    27-28 Sept,2012                        Chapter                              27
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.
                                MATLAB workshop under CSI Student
 27-28 Sept,2012                           Chapter                                     28
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.

                                MATLAB workshop under CSI Student
27-28 Sept,2012                            Chapter                         29
Operators (arithmetic)
    +     addition
    -     subtraction
    *     multiplication
    /     division
    ^     power
    „     transpose




                       MATLAB workshop under CSI Student
27-28 Sept,2012                   Chapter                  30
Matrices Operations


        Given A and B:



     Addition      Subtraction            Product            Transpose




                         MATLAB workshop under CSI Student
27-28 Sept,2012                     Chapter                              31
Operators (Element by Element)


    .* : element-by-element multiplication
    ./ : element-by-element division
    .^ : element-by-element power




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  32
The use of “.” – “Element” Operation
A = [1 2 3; 5 1 4; 3 2 1]
   A=
          1 2 3
          5 1 4
          3 2 -1

                                              b = x .* y          c=x./y          d = x .^2
x = A(1,:)             y = A(3 ,:)
                                              b=                  c=              d=
x=                     y=                          3 8 -3           0.33 0.5 -3        1   4        9
      1 2 3                 3 4 -1
         K= x^2
         Error:
         ??? Error using ==> mpower Matrix must be square.
         B=x*y
         Error:
         ??? Error using ==> mtimes Inner matrix dimensions must agree.
                                     MATLAB workshop under CSI Student
     27-28 Sept,2012                            Chapter                                        33
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)


                               MATLAB workshop under CSI Student
27-28 Sept,2012                           Chapter                  34
MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  35
Displaying Data/Text




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  36
Displaying Data/Text(cont…)




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  37
Displaying Data/Text(cont…)




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  38
Import/Export Data from Command




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  39
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
                       MATLAB workshop under CSI Student
27-28 Sept,2012                   Chapter                  40
Flow Control

          if
          for
          while
          break
           continue
           switch and case



                       MATLAB workshop under CSI Student
27-28 Sept,2012                   Chapter                  41
Control Structures
                                           Some Dummy Examples
        If Statement Syntax
                                           if ((a>3) & (b==5))
                                                Some Matlab Commands;
   if (Condition_1)                        end
          MATLAB Commands
                                           if (a<3)
   elseif (Condition_2)                         Some Matlab Commands;
           MATLAB Commands                 elseif (b~=5)
   elseif (Condition_3)                         Some Matlab Commands;
                                           end
           MATLAB Commands
   else                                    if (a<3)
                                                Some Matlab Commands;
           MATLAB Commands                 else
   end                                          Some Matlab Commands;
                                           end
                    MATLAB workshop under CSI Student
27-28 Sept,2012                Chapter                                  42
Control Structures
                                             Some Dummy Examples
    For loop syntax                         for i=1:100
for i=start: Last index                          Some Matlab Commands;
                                             end
    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
                          MATLAB workshop under CSI Student
27-28 Sept,2012                      Chapter                                 43
Control Structures
                                  Dummy Example
    While Loop Syntax            while ((a>3) & (b==5))
                                     Some Matlab Commands;
                                  end
while (condition)                 % while loop
                                  i=1;
  MATLAB Commands                 while(i<10)
                                       disp(i);
end                                    i=i+1;
                                  end




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                         44
Use of M-File
Click to create
a new M-File




  • Extension “.m”
  • A text file containing script or function or program to run
                        MATLAB workshop under CSI Student
 27-28 Sept,2012                   Chapter                        45
Switch and case




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  46
Continue statement




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  47
Break statement




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  48
Use of M-File                           Save file as Denem430.m




                                                      If you include “;” at the
                                                      end of each statement,
                                                      result will not be shown
                                                      immediately




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                                          49
Solution

>> A{1,1} = 'MATLAB ';
>> A{1,2} = 'SIMULINK ';
>> A = deblank(A)

A=

      'MATLAB'    'SIMULINK'

                   MATLAB workshop under CSI Student
27-28 Sept,2012               Chapter                  50
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

                  function out1=functionname(inp1)
                  function out1=functionname(inp1,inp2,inp3)
                  function [out1,out2]=functionname(inp1,inp2)


          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
                               MATLAB workshop under CSI Student
27-28 Sept,2012                           Chapter                  51
How to read a text file

fid = fopen('message.txt','r');
ice1= fread(fid);
s = char(ice1');
fclose(fid);
disp(s);

Ans   hello




                                  MATLAB workshop under CSI Student
27-28 Sept,2012                              Chapter                  52
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




                                MATLAB workshop under CSI Student
27-28 Sept,2012                            Chapter                  53
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




                             MATLAB workshop under CSI Student
27-28 Sept,2012                         Chapter                              54
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);

             >>x=linspace(0,4*pi,100);
         Calculate sin(.) of the x-array

              >>y=sin(x);
         Plot the y-array
             >>plot(y)

                               MATLAB workshop under CSI Student
27-28 Sept,2012                           Chapter                  55
Plot the function e-x/3sin(x) between
0≤x≤4π
      Create an x-array of 100 samples between 0
       and 4π.
         >>x=linspace(0,4*pi,100);

      Calculate sin(.) of the x-array
         >>y=sin(x);

      Calculate e-x/3 of the x-array
         >>y1=exp(-x/3);

      Multiply the arrays y and y1
          >>y2=y*y1;
                             MATLAB workshop under CSI Student
27-28 Sept,2012                         Chapter                  56
Plot the function e-x/3sin(x) between
0≤x≤4π
    Multiply the arrays y and y1 correctly
             >>y2=y.*y1;

    Plot the y2-array
                                                   0.7

             >>plot(y2)                            0.6

                                                   0.5

                                                   0.4

                                                   0.3

                                                   0.2

                                                   0.1

                                                    0

                                                  -0.1

                                                  -0.2

                                                  -0.3
                                                         0   10   20   30   40   50   60   70   80   90        100


                           MATLAB workshop under CSI Student
27-28 Sept,2012                       Chapter                                                             57
Display Facilities

    plot(par1,par2)                                       0.7

                                                           0.6

                                                           0.5

            Example:                                       0.4


            >>x=linspace(0,4*pi,100);                      0.3


            >>y=sin(x);
                                                           0.2

                                                           0.1

            >>plot(y)                                       0

            >>plot(x,y)                                   -0.1

                                                          -0.2

                                                          -0.3
                                                                 0   10   20   30   40   50   60   70   80   90    100




                              MATLAB workshop under CSI Student
27-28 Sept,2012                          Chapter                                                              58
Neural Network
                      (NN)



                    MATLAB workshop under CSI Student
27-28 Sept,2012                Chapter                  59
How to Design Neural Network

1.      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

                      MATLAB workshop under CSI Student
27-28 Sept,2012                  Chapter                  60
Simple              Neuron/1 st               layer Perceptron

                            b
     X1                     wb=1
              w1
                        E
                                          y

                   w2
      X2




                            MATLAB workshop under CSI Student
27-28 Sept,2012                        Chapter                   61
Transfer Function




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  62
Vectors used in NN




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  63
Neural Network Architecture




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  64
MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  65
MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  66
Multilayer NN




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  67
How to open Neural Network Tool

>>nftool




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  68
Graph Plot


                    MATLAB workshop under CSI Student
27-28 Sept,2012                Chapter                  69
Display Facilities

   title(.)
          >>title(‘This is the sinus function’)
                                                                                           This is the sinus function
                                                                   1

                                                                 0.8

   xlabel(.)                                                    0.6

                                                                 0.4

          >>xlabel(‘x (secs)’)                                   0.2




                                                        sin(x)
                                                                   0


   ylabel(.)                                                    -0.2

                                                                 -0.4

                                                                 -0.6

                                                                 -0.8
           >>ylabel(‘sin(x)’)                                     -1
                                                                        0   10   20   30       40      50    60         70   80   90    100
                                                                                                    x (secs)




                                    MATLAB workshop under CSI Student
    27-28 Sept,2012                            Chapter                                                                             70
GUI
                  (Graphical User Interface)




                       MATLAB workshop under CSI Student
27-28 Sept,2012                   Chapter                  71
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




                            MATLAB workshop under CSI Student
27-28 Sept,2012                        Chapter                            72
DIALOG BOX

        warndlg('hello');           helpdlg('hello');           errordlg('hello');




         msgbox('hello');




                            MATLAB workshop under CSI Student
27-28 Sept,2012                        Chapter                                       73
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




                                 MATLAB workshop under CSI Student
27-28 Sept,2012                             Chapter                  74
GUI…




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  75
PUSH BUTTON




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  76
TOGGLE BUTTON




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  77
RADIO BUTTON




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  78
CHECKBOX




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  79
EDIT TEXT




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  80
STATIC TEXT




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  81
SLIDER




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  82
FRAME




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  83
LISTBOX




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  84
POPUP MENU




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  85
AXES




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  86
ALIGN OBJECTS




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  87
MENU EDITOR




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  88
M FILE EDITOR




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  89
PROPERTY INSPECTOR




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  90
MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  91
RUN




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  92
PUSH BUTTON




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  93
WRITE THE CODE BELOW THE
 CALLBACK

a =imread('cameraman.tif');

imshow(a);




                              MATLAB workshop under CSI Student
 27-28 Sept,2012                         Chapter                  94
RUN THE PROGRAM OR PRESS F5




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  95
RIGHT CLICK PUSH BUTTON & GO FOR
PROPERTY INSPECTOR




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  96
CHOOSE AXES




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  97
RIGHT CLICK AXES & GO FOR
PROPERTY INSPECTOR




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  98
CHANGE THE STRING AND TAG
VALUE




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  99
WRITE THE CODE BELOW THE
  CALLBACK
a =imread('cameraman.tif');

axes(handles.one);

imshow(a);




                              MATLAB workshop under CSI Student
  27-28 Sept,2012                        Chapter                  100
RUN THE PROGRAM




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  101
CODE


 a =imread('cameraman.tif');

 axes(handles.one);

 imshow(a);




                           MATLAB workshop under CSI Student
27-28 Sept,2012                       Chapter                  102
TOGGLE BUTTON




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  103
RIGHT CLICK TOGGLE & GO FOR
PROPERTY INSPECTOR




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  104
CHANGE THE STRING AND TAG
VALUE




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  105
RIGHT CLICK TOGGLE & GO FOR M
FILE EDITOR




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  106
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

                                MATLAB workshop under CSI Student
27-28 Sept,2012                            Chapter                  107
RUN THE PROGRAM




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  108
RIGHT CLICK CHECK BOX & GO FOR
PROPERTY INSPECTOR




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  109
CHANGE THE STRING AND TAG
VALUE




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  110
RIGHT CLICK CHECK BOX & GO FOR M
FILE EDITOR




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  111
WRITE THE CODE BELOW THE
CALLBACK




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  112
RUN THE PROGRAM




                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  113
Image Processing




                     MATLAB workshop under CSI Student
27-28 Sept,2012                 Chapter                  114
How to read an image

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




                            MATLAB workshop under CSI Student
27-28 Sept,2012                        Chapter                           115
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)




                              MATLAB workshop under CSI Student
 27-28 Sept,2012                         Chapter                  116
How to read an audio file


 a =wavread('test.wav');
 wavplay(a,44100);
 Plot(a);




                     MATLAB workshop under CSI Student
27-28 Sept,2012                 Chapter                  117
How to read an video file


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




                             MATLAB workshop under CSI Student
27-28 Sept,2012                         Chapter                  118
Add two images

I = imread('rice.tif');
                                              I = imread('rice.tif');
J = imread('cameraman.tif');
K = imadd(I,J,'uint16');
                                               J = imadd(I,Irice50);
imshow(K,[])
                                               subplot(1,2,1), imshow(I)
                                               subplot(1,2,2), imshow(J)




                               MATLAB workshop under CSI Student
27-28 Sept,2012                           Chapter                          119
Subtract two images

I = imread('rice.tif');
 Iq = imsubtract(I,Irice50);
 subplot(1,2,1), imshow(I)
subplot(1,2,2), imshow(Iq)




                               MATLAB workshop under CSI Student
27-28 Sept,2012                           Chapter                  120
Convert image to gray and binary
  clc;
  clear;
  close all
  a= 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);




                              MATLAB workshop under CSI Student
27-28 Sept,2012                          Chapter                  121
RGB component
   a=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);


                              MATLAB workshop under CSI Student
27-28 Sept,2012                          Chapter                  122
Convert Image into One dimensional


a = imread('cameraman.tif');

[r c]=size(a);

Len=r*c;

b=reshape(a,[1 Len]);

                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  123
Counting the Number of Objects in an
Image
clc;
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
                                     MATLAB workshop under CSI Student
27-28 Sept,2012                                 Chapter                  124
Advantages and Disadvantages of MATLAB

    Advantages
         Ease of use
         Platform independence
         Predefined functions
         Plotting
    Disadvantages
         Can be slow
         Expensive


                        MATLAB workshop under CSI Student
27-28 Sept,2012                    Chapter                  125
Thank You…



                  MATLAB workshop under CSI Student
27-28 Sept,2012              Chapter                  126

Mais conteúdo relacionado

Mais procurados

Matlab for beginners, Introduction, signal processing
Matlab for beginners, Introduction, signal processingMatlab for beginners, Introduction, signal processing
Matlab for beginners, Introduction, signal processingDr. Manjunatha. P
 
Matlab day 1: Introduction to MATLAB
Matlab day 1: Introduction to MATLABMatlab day 1: Introduction to MATLAB
Matlab day 1: Introduction to MATLABreddyprasad reddyvari
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlabMohan Raj
 
Summer training matlab
Summer training matlab Summer training matlab
Summer training matlab Arshit Rai
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlabDnyanesh Patil
 
Matlab for Electrical Engineers
Matlab for Electrical EngineersMatlab for Electrical Engineers
Matlab for Electrical EngineersManish Joshi
 
Basics of programming in matlab
Basics of programming in matlabBasics of programming in matlab
Basics of programming in matlabAKANKSHA GUPTA
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLABAshish Meshram
 
MatLab Basic Tutorial On Plotting
MatLab Basic Tutorial On PlottingMatLab Basic Tutorial On Plotting
MatLab Basic Tutorial On PlottingMOHDRAFIQ22
 
Writing Fast MATLAB Code
Writing Fast MATLAB CodeWriting Fast MATLAB Code
Writing Fast MATLAB CodeJia-Bin Huang
 
Introduction to MATLAB 1
Introduction to MATLAB 1Introduction to MATLAB 1
Introduction to MATLAB 1Mohamed Gafar
 
Basics of MATLAB programming
Basics of MATLAB programmingBasics of MATLAB programming
Basics of MATLAB programmingRanjan Pal
 
Advanced MATLAB Tutorial for Engineers & Scientists
Advanced MATLAB Tutorial for Engineers & ScientistsAdvanced MATLAB Tutorial for Engineers & Scientists
Advanced MATLAB Tutorial for Engineers & ScientistsRay Phan
 
How to work on Matlab.......
How to work on Matlab.......How to work on Matlab.......
How to work on Matlab.......biinoida
 

Mais procurados (20)

Matlab for beginners, Introduction, signal processing
Matlab for beginners, Introduction, signal processingMatlab for beginners, Introduction, signal processing
Matlab for beginners, Introduction, signal processing
 
Image processing
Image processingImage processing
Image processing
 
Matlab day 1: Introduction to MATLAB
Matlab day 1: Introduction to MATLABMatlab day 1: Introduction to MATLAB
Matlab day 1: Introduction to MATLAB
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Matlab ppt
Matlab pptMatlab ppt
Matlab ppt
 
Summer training matlab
Summer training matlab Summer training matlab
Summer training matlab
 
Matlab
MatlabMatlab
Matlab
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Matlab for Electrical Engineers
Matlab for Electrical EngineersMatlab for Electrical Engineers
Matlab for Electrical Engineers
 
Basics of programming in matlab
Basics of programming in matlabBasics of programming in matlab
Basics of programming in matlab
 
Matlab
MatlabMatlab
Matlab
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
 
MATLAB & Image Processing
MATLAB & Image ProcessingMATLAB & Image Processing
MATLAB & Image Processing
 
MatLab Basic Tutorial On Plotting
MatLab Basic Tutorial On PlottingMatLab Basic Tutorial On Plotting
MatLab Basic Tutorial On Plotting
 
Writing Fast MATLAB Code
Writing Fast MATLAB CodeWriting Fast MATLAB Code
Writing Fast MATLAB Code
 
Introduction to MATLAB 1
Introduction to MATLAB 1Introduction to MATLAB 1
Introduction to MATLAB 1
 
Basics of MATLAB programming
Basics of MATLAB programmingBasics of MATLAB programming
Basics of MATLAB programming
 
What is matlab
What is matlabWhat is matlab
What is matlab
 
Advanced MATLAB Tutorial for Engineers & Scientists
Advanced MATLAB Tutorial for Engineers & ScientistsAdvanced MATLAB Tutorial for Engineers & Scientists
Advanced MATLAB Tutorial for Engineers & Scientists
 
How to work on Matlab.......
How to work on Matlab.......How to work on Matlab.......
How to work on Matlab.......
 

Semelhante a Two Days workshop on MATLAB

Introduction to Matlab.pdf
Introduction to Matlab.pdfIntroduction to Matlab.pdf
Introduction to Matlab.pdfssuser43b38e
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLABkalaimuthu2
 
interfacing matlab with embedded systems
interfacing matlab with embedded systemsinterfacing matlab with embedded systems
interfacing matlab with embedded systemsRaghav Shetty
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introductionAmeen San
 
From zero to MATLAB hero: Mastering the basics and beyond
From zero to MATLAB hero: Mastering the basics and beyondFrom zero to MATLAB hero: Mastering the basics and beyond
From zero to MATLAB hero: Mastering the basics and beyondMahuaPal6
 
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulinkMATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulinkreddyprasad reddyvari
 
Ppt 2 d ploting k10998
Ppt 2 d ploting k10998Ppt 2 d ploting k10998
Ppt 2 d ploting k10998Vinit Rajput
 
A MATLAB-Aided Method For Teaching Calculus-Based Business Mathematics
A MATLAB-Aided Method For Teaching Calculus-Based Business MathematicsA MATLAB-Aided Method For Teaching Calculus-Based Business Mathematics
A MATLAB-Aided Method For Teaching Calculus-Based Business MathematicsKate Campbell
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlabTarun Gehlot
 

Semelhante a Two Days workshop on MATLAB (20)

MATLAB guide
MATLAB guideMATLAB guide
MATLAB guide
 
Introduction to Matlab.pdf
Introduction to Matlab.pdfIntroduction to Matlab.pdf
Introduction to Matlab.pdf
 
Matlab anilkumar
Matlab  anilkumarMatlab  anilkumar
Matlab anilkumar
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
 
Matlab basic and image
Matlab basic and imageMatlab basic and image
Matlab basic and image
 
interfacing matlab with embedded systems
interfacing matlab with embedded systemsinterfacing matlab with embedded systems
interfacing matlab with embedded systems
 
Lecture 1.pptx
Lecture 1.pptxLecture 1.pptx
Lecture 1.pptx
 
Introduction to Matlab.ppt
Introduction to Matlab.pptIntroduction to Matlab.ppt
Introduction to Matlab.ppt
 
Matlab programming
Matlab programmingMatlab programming
Matlab programming
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
 
From zero to MATLAB hero: Mastering the basics and beyond
From zero to MATLAB hero: Mastering the basics and beyondFrom zero to MATLAB hero: Mastering the basics and beyond
From zero to MATLAB hero: Mastering the basics and beyond
 
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulinkMATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
 
An Introduction to MATLAB with Worked Examples
An Introduction to MATLAB with Worked ExamplesAn Introduction to MATLAB with Worked Examples
An Introduction to MATLAB with Worked Examples
 
Ppt 2 d ploting k10998
Ppt 2 d ploting k10998Ppt 2 d ploting k10998
Ppt 2 d ploting k10998
 
Mmc manual
Mmc manualMmc manual
Mmc manual
 
A MATLAB-Aided Method For Teaching Calculus-Based Business Mathematics
A MATLAB-Aided Method For Teaching Calculus-Based Business MathematicsA MATLAB-Aided Method For Teaching Calculus-Based Business Mathematics
A MATLAB-Aided Method For Teaching Calculus-Based Business Mathematics
 
Dsp file
Dsp fileDsp file
Dsp file
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
 
Google lme4
Google lme4Google lme4
Google lme4
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 

Último

Patient Counselling. Definition of patient counseling; steps involved in pati...
Patient Counselling. Definition of patient counseling; steps involved in pati...Patient Counselling. Definition of patient counseling; steps involved in pati...
Patient Counselling. Definition of patient counseling; steps involved in pati...raviapr7
 
Presentation on the Basics of Writing. Writing a Paragraph
Presentation on the Basics of Writing. Writing a ParagraphPresentation on the Basics of Writing. Writing a Paragraph
Presentation on the Basics of Writing. Writing a ParagraphNetziValdelomar1
 
HED Office Sohayok Exam Question Solution 2023.pdf
HED Office Sohayok Exam Question Solution 2023.pdfHED Office Sohayok Exam Question Solution 2023.pdf
HED Office Sohayok Exam Question Solution 2023.pdfMohonDas
 
Clinical Pharmacy Introduction to Clinical Pharmacy, Concept of clinical pptx
Clinical Pharmacy  Introduction to Clinical Pharmacy, Concept of clinical pptxClinical Pharmacy  Introduction to Clinical Pharmacy, Concept of clinical pptx
Clinical Pharmacy Introduction to Clinical Pharmacy, Concept of clinical pptxraviapr7
 
Quality Assurance_GOOD LABORATORY PRACTICE
Quality Assurance_GOOD LABORATORY PRACTICEQuality Assurance_GOOD LABORATORY PRACTICE
Quality Assurance_GOOD LABORATORY PRACTICESayali Powar
 
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...Nguyen Thanh Tu Collection
 
Philosophy of Education and Educational Philosophy
Philosophy of Education  and Educational PhilosophyPhilosophy of Education  and Educational Philosophy
Philosophy of Education and Educational PhilosophyShuvankar Madhu
 
How to Add Existing Field in One2Many Tree View in Odoo 17
How to Add Existing Field in One2Many Tree View in Odoo 17How to Add Existing Field in One2Many Tree View in Odoo 17
How to Add Existing Field in One2Many Tree View in Odoo 17Celine George
 
How to Manage Cross-Selling in Odoo 17 Sales
How to Manage Cross-Selling in Odoo 17 SalesHow to Manage Cross-Selling in Odoo 17 Sales
How to Manage Cross-Selling in Odoo 17 SalesCeline George
 
How to Solve Singleton Error in the Odoo 17
How to Solve Singleton Error in the  Odoo 17How to Solve Singleton Error in the  Odoo 17
How to Solve Singleton Error in the Odoo 17Celine George
 
UKCGE Parental Leave Discussion March 2024
UKCGE Parental Leave Discussion March 2024UKCGE Parental Leave Discussion March 2024
UKCGE Parental Leave Discussion March 2024UKCGE
 
2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx
2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx
2024.03.23 What do successful readers do - Sandy Millin for PARK.pptxSandy Millin
 
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdf
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdfP4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdf
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdfYu Kanazawa / Osaka University
 
Practical Research 1: Lesson 8 Writing the Thesis Statement.pptx
Practical Research 1: Lesson 8 Writing the Thesis Statement.pptxPractical Research 1: Lesson 8 Writing the Thesis Statement.pptx
Practical Research 1: Lesson 8 Writing the Thesis Statement.pptxKatherine Villaluna
 
The basics of sentences session 10pptx.pptx
The basics of sentences session 10pptx.pptxThe basics of sentences session 10pptx.pptx
The basics of sentences session 10pptx.pptxheathfieldcps1
 
What is the Future of QuickBooks DeskTop?
What is the Future of QuickBooks DeskTop?What is the Future of QuickBooks DeskTop?
What is the Future of QuickBooks DeskTop?TechSoup
 
Maximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdf
Maximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdfMaximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdf
Maximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdfTechSoup
 
General views of Histopathology and step
General views of Histopathology and stepGeneral views of Histopathology and step
General views of Histopathology and stepobaje godwin sunday
 
How to Make a Field read-only in Odoo 17
How to Make a Field read-only in Odoo 17How to Make a Field read-only in Odoo 17
How to Make a Field read-only in Odoo 17Celine George
 

Último (20)

Patient Counselling. Definition of patient counseling; steps involved in pati...
Patient Counselling. Definition of patient counseling; steps involved in pati...Patient Counselling. Definition of patient counseling; steps involved in pati...
Patient Counselling. Definition of patient counseling; steps involved in pati...
 
Presentation on the Basics of Writing. Writing a Paragraph
Presentation on the Basics of Writing. Writing a ParagraphPresentation on the Basics of Writing. Writing a Paragraph
Presentation on the Basics of Writing. Writing a Paragraph
 
HED Office Sohayok Exam Question Solution 2023.pdf
HED Office Sohayok Exam Question Solution 2023.pdfHED Office Sohayok Exam Question Solution 2023.pdf
HED Office Sohayok Exam Question Solution 2023.pdf
 
Clinical Pharmacy Introduction to Clinical Pharmacy, Concept of clinical pptx
Clinical Pharmacy  Introduction to Clinical Pharmacy, Concept of clinical pptxClinical Pharmacy  Introduction to Clinical Pharmacy, Concept of clinical pptx
Clinical Pharmacy Introduction to Clinical Pharmacy, Concept of clinical pptx
 
Quality Assurance_GOOD LABORATORY PRACTICE
Quality Assurance_GOOD LABORATORY PRACTICEQuality Assurance_GOOD LABORATORY PRACTICE
Quality Assurance_GOOD LABORATORY PRACTICE
 
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...
 
Philosophy of Education and Educational Philosophy
Philosophy of Education  and Educational PhilosophyPhilosophy of Education  and Educational Philosophy
Philosophy of Education and Educational Philosophy
 
How to Add Existing Field in One2Many Tree View in Odoo 17
How to Add Existing Field in One2Many Tree View in Odoo 17How to Add Existing Field in One2Many Tree View in Odoo 17
How to Add Existing Field in One2Many Tree View in Odoo 17
 
Finals of Kant get Marx 2.0 : a general politics quiz
Finals of Kant get Marx 2.0 : a general politics quizFinals of Kant get Marx 2.0 : a general politics quiz
Finals of Kant get Marx 2.0 : a general politics quiz
 
How to Manage Cross-Selling in Odoo 17 Sales
How to Manage Cross-Selling in Odoo 17 SalesHow to Manage Cross-Selling in Odoo 17 Sales
How to Manage Cross-Selling in Odoo 17 Sales
 
How to Solve Singleton Error in the Odoo 17
How to Solve Singleton Error in the  Odoo 17How to Solve Singleton Error in the  Odoo 17
How to Solve Singleton Error in the Odoo 17
 
UKCGE Parental Leave Discussion March 2024
UKCGE Parental Leave Discussion March 2024UKCGE Parental Leave Discussion March 2024
UKCGE Parental Leave Discussion March 2024
 
2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx
2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx
2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx
 
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdf
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdfP4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdf
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdf
 
Practical Research 1: Lesson 8 Writing the Thesis Statement.pptx
Practical Research 1: Lesson 8 Writing the Thesis Statement.pptxPractical Research 1: Lesson 8 Writing the Thesis Statement.pptx
Practical Research 1: Lesson 8 Writing the Thesis Statement.pptx
 
The basics of sentences session 10pptx.pptx
The basics of sentences session 10pptx.pptxThe basics of sentences session 10pptx.pptx
The basics of sentences session 10pptx.pptx
 
What is the Future of QuickBooks DeskTop?
What is the Future of QuickBooks DeskTop?What is the Future of QuickBooks DeskTop?
What is the Future of QuickBooks DeskTop?
 
Maximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdf
Maximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdfMaximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdf
Maximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdf
 
General views of Histopathology and step
General views of Histopathology and stepGeneral views of Histopathology and step
General views of Histopathology and step
 
How to Make a Field read-only in Odoo 17
How to Make a Field read-only in Odoo 17How to Make a Field read-only in Odoo 17
How to Make a Field read-only in Odoo 17
 

Two Days workshop on MATLAB

  • 1. Two Days workshop on MATLAB (MATrix LABoratory) [27-28 Sept, 2012] Presented By: Bhavesh Shah Asst. Prof., GF’s GCOE, Jalgaon
  • 2. 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 MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 2
  • 3. 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 MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 3
  • 4. Toolboxes provided By MATLAB 1. 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 MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 4
  • 5. Toolboxes provided By MATLAB 1. 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 MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 5
  • 6. 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 MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 6
  • 7. Structure of MATLAB MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 7
  • 8. 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 MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 8
  • 9. Useful Commands  The two commands used most by Matlab users are >>help functionname >>lookfor keyword MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 9
  • 10. Variables  No need for types. i.e., int a; double b; float c;  All variables are created with double precision unless specified and they are matrices. >>x=5; >>x1=2;  After these statements, the variables are 1x1 matrices with double precision. MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 10
  • 11. 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 MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 11
  • 12. 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 MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 12
  • 13. Variable(cont…) MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 13
  • 14. Array MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 14
  • 15. 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 MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 15
  • 16. 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 MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 16
  • 17. 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 MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 17
  • 18. Built-in Math function  abs, sign  log, log10, log2  exp  sqrt  sin, cos, tan  max, min  round, floor, ceil, fix  mod MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 18
  • 19. Built in Functions  sort  sortrows  mod(num,2) MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 19
  • 20. Built in function related to String MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 20
  • 21. MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 21
  • 22. Limit and Integration MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 22
  • 23. Differentiation MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 23
  • 24. Solving Equations >> solve('cos(2*x)+sin(x)=1') MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 24
  • 25. 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 MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 25
  • 26. 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) MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 26
  • 27. Generating Vectors from functions  zeros(M,N) MxN matrix of zeros x = zeros(1,3) x = 0 0 0  ones(M,N) MxN matrix of ones x = ones(1,3) x = 1 1 1  rand(M,N) MxN matrix of uniformly distributed random x = rand(1,3) numbers on (0,1) x = 0.9501 0.2311 0.6068 MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 27
  • 28. 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. MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 28
  • 29. 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. MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 29
  • 30. Operators (arithmetic) + addition - subtraction * multiplication / division ^ power „ transpose MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 30
  • 31. Matrices Operations Given A and B: Addition Subtraction Product Transpose MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 31
  • 32. Operators (Element by Element) .* : element-by-element multiplication ./ : element-by-element division .^ : element-by-element power MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 32
  • 33. The use of “.” – “Element” Operation A = [1 2 3; 5 1 4; 3 2 1] A= 1 2 3 5 1 4 3 2 -1 b = x .* y c=x./y d = x .^2 x = A(1,:) y = A(3 ,:) b= c= d= x= y= 3 8 -3 0.33 0.5 -3 1 4 9 1 2 3 3 4 -1 K= x^2 Error: ??? Error using ==> mpower Matrix must be square. B=x*y Error: ??? Error using ==> mtimes Inner matrix dimensions must agree. MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 33
  • 34. 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) MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 34
  • 35. MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 35
  • 36. Displaying Data/Text MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 36
  • 37. Displaying Data/Text(cont…) MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 37
  • 38. Displaying Data/Text(cont…) MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 38
  • 39. Import/Export Data from Command MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 39
  • 40. 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 MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 40
  • 41. Flow Control  if  for  while  break  continue  switch and case MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 41
  • 42. Control Structures Some Dummy Examples  If Statement Syntax if ((a>3) & (b==5)) Some Matlab Commands; if (Condition_1) end MATLAB Commands if (a<3) elseif (Condition_2) Some Matlab Commands; MATLAB Commands elseif (b~=5) elseif (Condition_3) Some Matlab Commands; end MATLAB Commands else if (a<3) Some Matlab Commands; MATLAB Commands else end Some Matlab Commands; end MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 42
  • 43. Control Structures Some Dummy Examples  For loop syntax for i=1:100 for i=start: Last index Some Matlab Commands; end 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 MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 43
  • 44. Control Structures Dummy Example  While Loop Syntax while ((a>3) & (b==5)) Some Matlab Commands; end while (condition) % while loop i=1; MATLAB Commands while(i<10) disp(i); end i=i+1; end MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 44
  • 45. Use of M-File Click to create a new M-File • Extension “.m” • A text file containing script or function or program to run MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 45
  • 46. Switch and case MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 46
  • 47. Continue statement MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 47
  • 48. Break statement MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 48
  • 49. Use of M-File Save file as Denem430.m If you include “;” at the end of each statement, result will not be shown immediately MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 49
  • 50. Solution >> A{1,1} = 'MATLAB '; >> A{1,2} = 'SIMULINK '; >> A = deblank(A) A= 'MATLAB' 'SIMULINK' MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 50
  • 51. 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 function out1=functionname(inp1) function out1=functionname(inp1,inp2,inp3) function [out1,out2]=functionname(inp1,inp2)  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 MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 51
  • 52. How to read a text file fid = fopen('message.txt','r'); ice1= fread(fid); s = char(ice1'); fclose(fid); disp(s); Ans hello MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 52
  • 53. 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 MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 53
  • 54. 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 MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 54
  • 55. 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); >>x=linspace(0,4*pi,100);  Calculate sin(.) of the x-array >>y=sin(x);  Plot the y-array >>plot(y) MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 55
  • 56. Plot the function e-x/3sin(x) between 0≤x≤4π  Create an x-array of 100 samples between 0 and 4π. >>x=linspace(0,4*pi,100);  Calculate sin(.) of the x-array >>y=sin(x);  Calculate e-x/3 of the x-array >>y1=exp(-x/3);  Multiply the arrays y and y1 >>y2=y*y1; MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 56
  • 57. Plot the function e-x/3sin(x) between 0≤x≤4π  Multiply the arrays y and y1 correctly >>y2=y.*y1;  Plot the y2-array 0.7 >>plot(y2) 0.6 0.5 0.4 0.3 0.2 0.1 0 -0.1 -0.2 -0.3 0 10 20 30 40 50 60 70 80 90 100 MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 57
  • 58. Display Facilities  plot(par1,par2) 0.7 0.6 0.5 Example: 0.4 >>x=linspace(0,4*pi,100); 0.3 >>y=sin(x); 0.2 0.1 >>plot(y) 0 >>plot(x,y) -0.1 -0.2 -0.3 0 10 20 30 40 50 60 70 80 90 100 MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 58
  • 59. Neural Network (NN) MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 59
  • 60. How to Design Neural Network 1. 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 MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 60
  • 61. Simple Neuron/1 st layer Perceptron b X1 wb=1 w1 E y w2 X2 MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 61
  • 62. Transfer Function MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 62
  • 63. Vectors used in NN MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 63
  • 64. Neural Network Architecture MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 64
  • 65. MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 65
  • 66. MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 66
  • 67. Multilayer NN MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 67
  • 68. How to open Neural Network Tool >>nftool MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 68
  • 69. Graph Plot MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 69
  • 70. Display Facilities  title(.) >>title(‘This is the sinus function’) This is the sinus function 1 0.8  xlabel(.) 0.6 0.4 >>xlabel(‘x (secs)’) 0.2 sin(x) 0  ylabel(.) -0.2 -0.4 -0.6 -0.8 >>ylabel(‘sin(x)’) -1 0 10 20 30 40 50 60 70 80 90 100 x (secs) MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 70
  • 71. GUI (Graphical User Interface) MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 71
  • 72. 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 MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 72
  • 73. DIALOG BOX warndlg('hello'); helpdlg('hello'); errordlg('hello'); msgbox('hello'); MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 73
  • 74. 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 MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 74
  • 75. GUI… MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 75
  • 76. PUSH BUTTON MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 76
  • 77. TOGGLE BUTTON MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 77
  • 78. RADIO BUTTON MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 78
  • 79. CHECKBOX MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 79
  • 80. EDIT TEXT MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 80
  • 81. STATIC TEXT MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 81
  • 82. SLIDER MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 82
  • 83. FRAME MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 83
  • 84. LISTBOX MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 84
  • 85. POPUP MENU MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 85
  • 86. AXES MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 86
  • 87. ALIGN OBJECTS MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 87
  • 88. MENU EDITOR MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 88
  • 89. M FILE EDITOR MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 89
  • 90. PROPERTY INSPECTOR MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 90
  • 91. MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 91
  • 92. RUN MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 92
  • 93. PUSH BUTTON MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 93
  • 94. WRITE THE CODE BELOW THE CALLBACK a =imread('cameraman.tif'); imshow(a); MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 94
  • 95. RUN THE PROGRAM OR PRESS F5 MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 95
  • 96. RIGHT CLICK PUSH BUTTON & GO FOR PROPERTY INSPECTOR MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 96
  • 97. CHOOSE AXES MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 97
  • 98. RIGHT CLICK AXES & GO FOR PROPERTY INSPECTOR MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 98
  • 99. CHANGE THE STRING AND TAG VALUE MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 99
  • 100. WRITE THE CODE BELOW THE CALLBACK a =imread('cameraman.tif'); axes(handles.one); imshow(a); MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 100
  • 101. RUN THE PROGRAM MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 101
  • 102. CODE a =imread('cameraman.tif'); axes(handles.one); imshow(a); MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 102
  • 103. TOGGLE BUTTON MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 103
  • 104. RIGHT CLICK TOGGLE & GO FOR PROPERTY INSPECTOR MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 104
  • 105. CHANGE THE STRING AND TAG VALUE MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 105
  • 106. RIGHT CLICK TOGGLE & GO FOR M FILE EDITOR MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 106
  • 107. 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 MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 107
  • 108. RUN THE PROGRAM MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 108
  • 109. RIGHT CLICK CHECK BOX & GO FOR PROPERTY INSPECTOR MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 109
  • 110. CHANGE THE STRING AND TAG VALUE MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 110
  • 111. RIGHT CLICK CHECK BOX & GO FOR M FILE EDITOR MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 111
  • 112. WRITE THE CODE BELOW THE CALLBACK MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 112
  • 113. RUN THE PROGRAM MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 113
  • 114. Image Processing MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 114
  • 115. How to read an image a =imread('cameraman.tif'); a =imread('flowers.tif'); imshow(a); imshow(a); pixval on; pixval on; MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 115
  • 116. 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) MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 116
  • 117. How to read an audio file a =wavread('test.wav'); wavplay(a,44100); Plot(a); MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 117
  • 118. How to read an video file a=aviread('movie.avi'); movie(a); MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 118
  • 119. Add two images I = imread('rice.tif'); I = imread('rice.tif'); J = imread('cameraman.tif'); K = imadd(I,J,'uint16'); J = imadd(I,Irice50); imshow(K,[]) subplot(1,2,1), imshow(I) subplot(1,2,2), imshow(J) MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 119
  • 120. Subtract two images I = imread('rice.tif'); Iq = imsubtract(I,Irice50); subplot(1,2,1), imshow(I) subplot(1,2,2), imshow(Iq) MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 120
  • 121. Convert image to gray and binary clc; clear; close all a= 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); MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 121
  • 122. RGB component a=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); MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 122
  • 123. Convert Image into One dimensional a = imread('cameraman.tif'); [r c]=size(a); Len=r*c; b=reshape(a,[1 Len]); MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 123
  • 124. Counting the Number of Objects in an Image clc; 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 MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 124
  • 125. Advantages and Disadvantages of MATLAB  Advantages  Ease of use  Platform independence  Predefined functions  Plotting  Disadvantages  Can be slow  Expensive MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 125
  • 126. Thank You… MATLAB workshop under CSI Student 27-28 Sept,2012 Chapter 126