1 of 20

Cell Array, Debugging MATLAB programs, applications to simulations

COM 103 ICT Applications in Food Industry (1+2)

Lecture Schedule 5 – Part - V

Dr. S. Sridevy, Ph.D.

Assistant Professor (Computer Science)

Dept. of Physical Sciences & IT

AEC&RI, TNAU, Coimbatore – 3.

13 July 2020

2 of 20

Cell Array

  • The cell array is an array in which each element is a bin, or cell, which can contain an array.
  • Can store different classes of arrays in a cell array, and can group data sets that are related but have different dimensions.
  • Cell arrays can accessed using the same indexing operations used with ordinary arrays.

S. Sridevy

13 July 2020

3 of 20

Creating Cell Arrays

  • You can create a cell array by using assignment statements or by using the cell function.
  • You can assign data to the cells by using either cell indexing or content indexing.
  • To use cell indexing, enclose in parentheses the cell subscripts on the left side of the assignment statement and use the standard array notation.
  • Enclose the cell contents on the right side of the assignment statement in braces {}.

S. Sridevy

13 July 2020

4 of 20

Creating Cell Arrays (Contd.)

  • Suppose you want to create a 2 X 2 cell array A, whose cells contain the location, the date, the air temperature (measured at 8 A.M., 12 noon, and 5 P.M.), and the water temperatures measured at the same time in three different points in a pond. The cell array looks like the following.

S. Sridevy

13 July 2020

5 of 20

Creating Cell Arrays (Contd.)

  • You can create this array by typing the following either in interactive mode or in a script file and running it.

A(1,1) = {‘Walden Pond’};

A(1,2) = {‘June 13, 1997’};

A(2,1) = {[60,72,65]};

A(2,2) = {[55,57,56;54,56,55;52,55,53]};

S. Sridevy

13 July 2020

6 of 20

Creating Cell Arrays (Contd.)

  • If you do not yet have contents for a particular cell, you can type a pair of empty braces { } to denote an empty cell, just as a pair of empty brackets [] denotes an empty numeric array.
  • This notation creates the cell but does not store any contents in it.

S. Sridevy

13 July 2020

7 of 20

Creating Cell Arrays (Contd.)

  • To use content indexing, enclose in braces the cell subscripts on the left side, using the standard array notation.
  • Then specify the cell contents on the right side of the assignment

A{1,1} = ‘Walden Pond’;

A{1,2} = ‘June 13, 1997’;

A{2,1} = [60,72,65];

A{2,2} = [55,57,56;54,56,55;52,55,53];

Type A at the command line. You will see

A =

‘Walden Pond’ ‘June 13, 1997’

[1x3 double] [3x3 double]

S. Sridevy

13 July 2020

8 of 20

Creating Cell Arrays (Contd.)

  • You can use the celldisp function to display the full contents.
  • celldisp(A) displays

A{1,1} =

Walden Pond

A{2,1} =

60 72 65

.

.

.

etc.

S. Sridevy

13 July 2020

9 of 20

Debugging MATLAB Programs

  • Debugging is the process of identifying and removing errors from computer hardware or software.
  • MATLAB programs are often short because of the power of the commands, and may not need to use the Debugger unless programs are large.

S. Sridevy

13 July 2020

10 of 20

Editor/Debugger Menu Bar

  • Editor/Debugger Menu Bar has the following menu items:

File, Edit, Text, Go, Cell, Tools, Debug, Desktop, Window, and Help.

  • File, Edit, Desktop, Window, and Help menus are similar to those in the Desktop.
  • Go menu lets go backward or forward in the file.
  • The Tools menu involves advanced topics
  • Desktop menu is similar to that in the Command window. It enables to dock and undock windows, arrange the Editor window, and turn the Editor toolbar on and off.

S. Sridevy

13 July 2020

11 of 20

Editor/Debugger Menu Bar

  • The Text menu supplements the Edit menu for creating M- les.
  • With the Text menu you can insert or remove comments, increase or decrease the amount of indenting, turn on smart indenting, and evaluate and display the values of selected variables in the Command window.
  • Click anywhere in a previously typed line, and then click Comment in the Text menu. This makes the entire line a comment.
  • To turn a commented line into an executable line, click anywhere in the line, and then click Uncomment in the Text menu.

S. Sridevy

13 July 2020

12 of 20

Cell

  • A cell is a group of commands. (Not the cell array)
  • Type the double percent character (%%) to mark the beginning of a new cell; it is called a cell divider.
  • The cell mode is enabled when you first enter your program into the Editor .
  • To disable cell mode,click the Cell button and select Disable Cell Mode.

S. Sridevy

13 July 2020

13 of 20

Cell Mode (Contd.)

S. Sridevy

13 July 2020

14 of 20

Cell Mode (Contd.)

  • After entering and saving the program, you can click on one of the evaluation icons shown on the left-hand side of the cell toolbar .
  • These enable you to evaluate the current single cell (where the cursor is currently), to evaluate the current cell and advance to the next cell, or to evaluate the entire program.

S. Sridevy

13 July 2020

15 of 20

Cell Mode (Contd.)

  • A useful feature of cell mode is that it enables you to evaluate the results of changing a parameter.
  • For example, in Figure, suppose the cursor is next to the number -8. If you click the plus (+) or minus (-) sign in the cell toolbar, the parameter (-8) will be decremented or incremented.
  • If you have already run the program and the quadratic plot is on the screen, click the minus sign once to change the parameter from -8 to -9 and watch the plot change.

S. Sridevy

13 July 2020

16 of 20

Debug Menu

  • Breakpoints are points in the file where execution stops temporarily so that you can examine the values of the variables up to that point.
  • You set breakpoints with the Set/Clear Breakpoint item on the Debug menu.
  • Click Step to watch the script execute one step at a time.
  • Click Step In to step into the first executable line in a function being called.
  • Click Step Out in a called function to run the rest of the function and then return to the calling program.
  • Try Go Until Cursor, Exit Debug Mode

S. Sridevy

13 July 2020

17 of 20

Applications of Simulation

  • Simulation is the process of building and analyzing the output of computer programs that describe the operations of an organization, process, or physical system.
  • Such a program is called a computer model.

S. Sridevy

13 July 2020

18 of 20

Applications of Simulation (Contd.)

  • Simulation is often used in operations research, which is the quantitative study of an organization in action, to find ways to improve the functioning of the organization.
  • Simulation enables engineers to study the past, present, and future actions of the organization for this purpose.
  • Operations research techniques are useful in all engineering fields.

S. Sridevy

13 July 2020

19 of 20

Applications of Simulation (Contd.)

  • Common examples include airline scheduling, traffic flow studies, and production lines.
  • The MATLAB logical operators and loops are excellent tools for building simulation programs.

S. Sridevy

13 July 2020

20 of 20

Develop the simulation model

  • A certain college wants to analyze the effect of admissions and freshman retention rate on the college’s enrolment so that it can predict the future need for instructors and other resources. Assume that the college has estimates of the percentages of students repeating a grade or leaving school before graduating. Develop a matrix equation on which to base a simulation model that can help in this analysis.

S. Sridevy

13 July 2020

Thank You!