# MATLAB BASICS

This is a brief section on how to use MATLAB. It introduces the basic interface, variable types, efficient computation and solution display through m-files, potential uses. The focus is on a beginner who needs to be able to use the software to support simple undergraduate engineering problem solving, rather than on an advanced user. The first resource in **Basics 2** gives a rapid introduction to the potential and is less a learning tool than for motivation. After this each resource is focussed on just one aspect at a time.

It is implicit in several of these chapters that students have core competence in any related mathematical or engineering topics. This chapter contains the topics listed below. Under each topic there are hardcopy (pdf) notes, m-files and a video talk through with key illustrations done real time on MATLAB. |

- Matlab Basics 2 - introduction to simple calculations and use.
- Matlab Basics 3 - matrices, vectors and arrays.
- Matlab Basics 4 - script files.
- Matlab Basics 5 - variable types.
- Matlab Basics 6 - plotting.
- Matlab Basics 7 - symbolic variables.
- Matlab Basics extra - interface and window sizing.
- Matlab Basics 8 - conditionals.
- Matlab Basics 9 - loops.
- Matlab Basics 10 - function files.
- Matlab Basics 11 - producing figures for reports.

## Matlab Basics 2 - introduction to simple calculations and use

Demonstrates the potential of MATLAB and hopefully enthuses viewers to learn the details given in later resources. Shows how to do simple mathematical computations in MATLAB and that these are far easier than on a conventional hand calculator, especially where expressions are long or complicated. Demonstrates how expressions can be saved or recalled and editted to make error correction and repeated computation efficient. Demonstrates with live MATLAB usage. Some aspects such as symbolic variables and script files are introduced very concisely to demonstrate the power and potential of MATLAB but viewers should use the later resources for a slower and more careful explanation of these aspects.

- A summary of underlying powerpoint file is here pdf file.
- A talk through video is on youtube.
- The m-files mentioned in the video are available here for download. matlab_basics2.m, matlab_basics2b.m.

## Matlab Basics 3 - matrices, vectors and arrays

Introduces the main variable type in MATLAB which is the matrix. Shows how numerical values are stored, accessed (or indexed), editted and created. Demonstrates with live MATLAB usage. To keep the lengths reasonable, comprises two separate videos covering vectors and then matrices; ideally these are viewed in order.

- A summary of underlying powerpoint files are here vectors and here for matrices.
- A talk through video on vectors in MATLAB.
- A talk through video on matrices in MATLAB.
- The m-files mentioned in the video are available here for download. matlab_basics3, matlab_basics3b.m.

## Matlab Basics 4 - script files

Many engineering algorithms require a number of steps, done in a specific sequence. This resource demonstrates how a sequence commands can be stored in a m-file and then executed with a single button press, thus being very efficient. Also demonstrates with live MATLAB usage how errors can be captured and corrected very efficiently.

- A summary of underlying powerpoint file is here pdf file.
- A talk through video is on youtube.
- The m-files mentioned in the video are available here for download. matlab_basics4a.m, matlab_basics4b.m, matlab_basics4c.m, matlab_basics4d.m, matlab_basics4e.m.

## Matlab Basics 5 - variable types

Different types of problems require different types of variable (real number, complex number, integer, transfer function, matrix, string, etc.). This resource introduces a number of different variable types available on MATLAB and briefly demonstrates their use with some real time illustrations. As this resource covers a broad range of variables, the intention is not to give a comprehensive training in the different variable types, but rather to raise user awareness of the possibilities so they know where to look should the need arise.

- A summary of underlying powerpoint file is here pdf file.
- A talk through video is on youtube.
- The m-files mentioned in the video are available here for download: matlab_basics5.

## Matlab Basics 6 - plotting

Display of information is a core communication tool for engineers. This resource introduces the plot command in MATLAB and shows how easily plots can be created, modified, saved and exported for use in other software. Gives a number of live demonstrations and some supporting code for students to access and use as a template.

(i) Simple lines plots are around 2-4 min; (ii) Colours and line types are 4-6min; (iii) Labels, titles and legends 6-9min; (iv) Overlaying numerous plots 9-14min; (v) property editor 14-15min; (vi) subplots 15-17min; (vii) exporting to word processors 17min and (viii) live demonstrations 18-22min.

- A summary of underlying powerpoint file is here pdf file.
- A talk through video is on youtube.
- The m-files mentioned in the video are available here for download; matlab_basics6a, matlab_basics6b.m.

## Matlab Basics 7 - symbolic variables

Many engineering problems require algebraic manipulation, differentiation, roots solving and so on, all of which are tedious on pen and paper. This resource shows how MATLAB supports basic algebra and also, allows the algebra to be converted to numerical values where required. Differentiation and integration is around 2-5 min, Tangents around 6min, Taylor series around 8min, live demonstrations 11-18 min (with a focus on subs.m around 14.30 and 17.20).

- A talk through video is on youtube.
- A summary of underlying powerpoint file is here pdf file.
- The m-files mentioned in the video are available here for download. matlab_basics7, matlab_basics7b.m.

## Matlab Basics extra - interface and window sizing

Demonstrates the basic MATLAB interface and the different windows which open. Discusses different screen layouts and how one can exploit these to ensure the layout is the most efficient one for the given task. This can be skipped by users who feel the content is largely intuitive or obvious

- A summary of underlying powerpoint file is here pdf file.
- A talk through video is on youtube.
- The m-files mentioned in the video are available here for download. matlab_basics1.m, matlab_basics1b.m.

## Matlab Basics 8 - conditionals

A typical engineering algorithm or procedure will involve some decision making process, for example if it is hot, turning the central heating off. This resource shows how MATLAB enables decision making to be embedded efficiently and intuitively in any sequences of commands. Four videos look at four mains concepts: the use of if - else - end statements, the use of while - end statements, the use of switch - case - end statements and the use of logical variables.

## Matlab Basics 9 - loops.

There are numerous occasions where the same sequence of commands needs to be executed on several different values (such as when generating a plot or table). MATLAB provides a loop structure for supporting this. This resources demonstates the for loop structure and provides several m-files for students to use as templates to practice with.

Notes, youtube video, matlab_basics9a.m, matlab_basics9b.m, matlab_basics9c.m, matlab_basics9d.m, matlab_basics9e.m, matlab_basics9f.m.

## Matlab Basics 10 - function files

A core requirement in the long term is to save validated code for reuse later. In order to ensure this code cannot interfere with other code and computations, the recommended format is a function file which takes given inputs, executes a specifed sequence of commands (algorithm) on these, and produces the required output. This resource introduces the function file syntax and provides several illustrations and exemplars.

Notes, youtube video, matlab_basics10a.m, matlab_basics10b.m.

## Matlab basics 11 - producing figures for reports

Many students use MATLAB to produce figures for reports, presentations and posters, but do this poorly. This video gives some simple hints on how to ensure the image that appears in your report is easy to read, well produced and with appropriately sized fonts throughout.

Notes, youtube video, matlab_basics11.m, matlab_basics11b.m.