View by Category

The presentation will start after a short

(15 second) video ad from one of our sponsors.

Hot tip: Video ads won’t appear to registered users who are logged in. And it’s free to register and free to log in!

(15 second) video ad from one of our sponsors.

Hot tip: Video ads won’t appear to registered users who are logged in. And it’s free to register and free to log in!

Loading...

PPT – MATLAB Programming PowerPoint presentation | free to download - id: 1949c6-MjU1O

The Adobe Flash plugin is needed to view this content

About This Presentation

Write a Comment

User Comments (0)

Transcript and Presenter's Notes

MATLAB Programming

- COMM2M
- Harry R. Erwin, PhD
- University of Sunderland

Sources

- James E. Gentle, 2002, Elements of Computational

Statistics, Springer.

Topics

- Operators and Flow Control
- M-Files
- Functions
- Input and Output
- M-File Style
- Optimization
- Tutorial
- Individual Project

Operators and Flow Control

- Relational and Logical Operators
- Flow Control

Relational Operators

- The six relational operators are
- (equal)
- (not equal)
- lt
- gt
- lt
- gt
- True is 1 and false is 0
- Comparisons involving matrices produce matrices.

Logical Functions

- ischar
- isempty
- isequal
- isfinite
- isieee
- isinf

- islogical
- isnan
- isnumeric
- isreal
- issparse

Logical Operators

- (logical and)
- (logical or)
- (logical not)
- xor (logical exclusive or)
- all (true if all elements of vector are nonzero)
- any (true if any element of vector is nonzero)

Find

- The find() command returns the indices

corresponding to the non-zero elements of a

vector. Applied to a matrix M, it works with

M(). - This can be used with any of these functions and

operators. - If f was generated by f find(X), then X(f) are

the non-zero elements of X.

If Then Else

- if expression (handled like C/C/Java)
- statements (comma separated on one line)
- elseif expression2 (optional)
- elseif statements
- else (optional)
- final set of statements
- end

For Loop

- Convenient (but avoid if performance-critical

use vectors instead) - for variable expression
- for statements (, sep if 1 line)
- end
- Expression is usually isj. It can be a matrix,

in which case the columns from first to last are

used.

While Loop

- while expression
- statements
- end
- As long as expression remains true (0)
- for and while loops can be terminated with a

break. - continue jumps back to the loop start.
- Infinite loop
- while 1, , end

Switch Statement

- switch expression
- case value1 statements
- case value2 statements
- case value3 statements
- otherwise statements (optional)
- end
- The case value can be a value list within

forming a cell array. - This is different from C!!!!!

M-Files

- Scriptsno input or output arguments and operate

on variables in the workspace - Functionscontain a function definition line and

can work with input and output arguments.

Internal variables are local unless declared

global.

Scripts

- Format for a script called spin.m
- SPIN
- describes what it does
- executable statements

Functions

- function retval name(arguments)
- NAME one line description. (H1 line)
- more details including arguments
- code statements, eventually setting retval
- The name of the m-file should be the name of the

function. - The H1 line should omit the and a. It should

start with a capital letter and end with .. - There is usually a blank line after the header.
- The return command can be used to exit.

Editing M-Files

- M-files are ASCII files, so you can use any text

editor. - MATLAB has a built-in editor/debugger.
- Type edit
- Or use the menu in Windows systems.
- MATLAB maintains a search path to find M-files.

Use the path and addpath commands. There is also

a path browser that can be called by pathtool. - Relevant commands available include what,

lookfor, help, type, exist, and more.

Function Details

- Functions can be passed as argument to other

functions. Such an argument is preceded by _at_,

e.g., _at_fun. Handle it using feval. - Functions can also be passed as name strings.

This is not preferred. - The vectorize() function can be used to convert

multiplication, division, and exponentiation to

array operations

Subfunctions

- Any M-file can contain local functions after the

first one that can be called by the first one or

other subfunctions. - Usually you head a subfunction with
- Subfunction
- Subfunctions can be arguments.
- Functions and subfunctions can call themselves

recursively.

Input and Output

- User input
- Screen display
- Reading and writing text files

User Input

- The input function will display a prompt and wait

for user input. Input is interpreted as a string

if input is called with a second argument s. - The function ginput collects data via mouse click

coordinates. - The function pause() suspends execution until a

key is clicked. pause(n) waits n seconds.

Screen Display

- If you dont append a there will be output to

the screen. - The disp(var) function displays var.
- The fprintf function gives more sophisticated

control. - The sprintf function returns a string that

fprintf would have printed.

Text Files

- Type help iofun for the list of functions that

support text and binary file io. - These are generally similar to C functions.

M-File Style

- Be careful to fully document your files. In

particular, provide an example of how the

function can be used that can be cut and pasted. - Space around logical operators and
- One statement per line
- Indentation to emphasize structure.
- Matrix names should be capitalized.

Optimization

- You may compile M-files.
- Vectorize, dont shade your eyes
- n 5e5 x randn(n,1)
- tic, s 0 for i1n, s sx(i)2 end, toc
- Elapsed time 8.35
- tic, s sum(x.2) toc
- Elapsed time 0.06

More Optimization

- Preallocate large arrays. Otherwise they may be

expanded one row/column at a time. - The repmat function is much faster than anything

that involves manipulating individual matrix

entries. - Empty arrays/matrices are handled by

extrapolating operations on non-empty ones. This

may be very convenient.

Grand Tour Tutorial

- When a cluster of data points is rotated,

patterns in the data may become apparent. - Rotations are orthogonal transformations that

preserve the norms of the data vectors and the

angles between. - Simple rotation matrices start with the identity

matrix and change the four elements aii, aij,

aji, and ajj. aii and ajj are replaced with

cos(?), aij becomes sin(?), and aji becomes

-sin(?).

Generalized Rotation Matrices

- A generalized rotation matrix, Q, is the product

of (d2-d)/2 such simple rotation matrices. - Q Q12Q13Q1dQ23Q24Q2dQd-1,d

Constructing the Plot

- Rotating a plot in all directions, and projecting

into the first two or three dimensions is called

a Grand Tour (Asimov 1985). - You can take for the values of ?ij,
- t?ij modulo 2?
- where the ?ij are linearly independent over the

integers. Suitable constants are the square roots

of the first (d2-d)/2 primes. - Plot the first two (or three) dimensions.
- Suitable data can be found here

lthttp//lib.stat.cmu.edu/gt - Step time and observe the changes.

Suitable Data Can Be Found At

- lthttp//lib.stat.cmu.edu/gt

About PowerShow.com

PowerShow.com is a leading presentation/slideshow sharing website. Whether your application is business, how-to, education, medicine, school, church, sales, marketing, online training or just for fun, PowerShow.com is a great resource. And, best of all, most of its cool features are free and easy to use.

You can use PowerShow.com to find and download example online PowerPoint ppt presentations on just about any topic you can imagine so you can learn how to improve your own slides and presentations for free. Or use it to find and download high-quality how-to PowerPoint ppt presentations with illustrated or animated slides that will teach you how to do something new, also for free. Or use it to upload your own PowerPoint slides so you can share them with your teachers, class, students, bosses, employees, customers, potential investors or the world. Or use it to create really cool photo slideshows - with 2D and 3D transitions, animation, and your choice of music - that you can share with your Facebook friends or Google+ circles. That's all free as well!

For a small fee you can get the industry's best online privacy or publicly promote your presentations and slide shows with top rankings. But aside from that it's free. We'll even convert your presentations and slide shows into the universal Flash format with all their original multimedia glory, including animation, 2D and 3D transition effects, embedded music or other audio, or even video embedded in slides. All for free. Most of the presentations and slideshows on PowerShow.com are free to view, many are even free to download. (You can choose whether to allow people to download your original PowerPoint presentations and photo slideshows for a fee or free or not at all.) Check out PowerShow.com today - for FREE. There is truly something for everyone!

You can use PowerShow.com to find and download example online PowerPoint ppt presentations on just about any topic you can imagine so you can learn how to improve your own slides and presentations for free. Or use it to find and download high-quality how-to PowerPoint ppt presentations with illustrated or animated slides that will teach you how to do something new, also for free. Or use it to upload your own PowerPoint slides so you can share them with your teachers, class, students, bosses, employees, customers, potential investors or the world. Or use it to create really cool photo slideshows - with 2D and 3D transitions, animation, and your choice of music - that you can share with your Facebook friends or Google+ circles. That's all free as well!

For a small fee you can get the industry's best online privacy or publicly promote your presentations and slide shows with top rankings. But aside from that it's free. We'll even convert your presentations and slide shows into the universal Flash format with all their original multimedia glory, including animation, 2D and 3D transition effects, embedded music or other audio, or even video embedded in slides. All for free. Most of the presentations and slideshows on PowerShow.com are free to view, many are even free to download. (You can choose whether to allow people to download your original PowerPoint presentations and photo slideshows for a fee or free or not at all.) Check out PowerShow.com today - for FREE. There is truly something for everyone!

presentations for free. Or use it to find and download high-quality how-to PowerPoint ppt presentations with illustrated or animated slides that will teach you how to do something new, also for free. Or use it to upload your own PowerPoint slides so you can share them with your teachers, class, students, bosses, employees, customers, potential investors or the world. Or use it to create really cool photo slideshows - with 2D and 3D transitions, animation, and your choice of music - that you can share with your Facebook friends or Google+ circles. That's all free as well!

For a small fee you can get the industry's best online privacy or publicly promote your presentations and slide shows with top rankings. But aside from that it's free. We'll even convert your presentations and slide shows into the universal Flash format with all their original multimedia glory, including animation, 2D and 3D transition effects, embedded music or other audio, or even video embedded in slides. All for free. Most of the presentations and slideshows on PowerShow.com are free to view, many are even free to download. (You can choose whether to allow people to download your original PowerPoint presentations and photo slideshows for a fee or free or not at all.) Check out PowerShow.com today - for FREE. There is truly something for everyone!

For a small fee you can get the industry's best online privacy or publicly promote your presentations and slide shows with top rankings. But aside from that it's free. We'll even convert your presentations and slide shows into the universal Flash format with all their original multimedia glory, including animation, 2D and 3D transition effects, embedded music or other audio, or even video embedded in slides. All for free. Most of the presentations and slideshows on PowerShow.com are free to view, many are even free to download. (You can choose whether to allow people to download your original PowerPoint presentations and photo slideshows for a fee or free or not at all.) Check out PowerShow.com today - for FREE. There is truly something for everyone!

Recommended

«

/ »

Page of

«

/ »

Promoted Presentations

Related Presentations

Page of

Page of

CrystalGraphics Sales Tel: (800) 394-0700 x 1 or Send an email

Home About Us Terms and Conditions Privacy Policy Contact Us Send Us Feedback

Copyright 2016 CrystalGraphics, Inc. — All rights Reserved. PowerShow.com is a trademark of CrystalGraphics, Inc.

Copyright 2016 CrystalGraphics, Inc. — All rights Reserved. PowerShow.com is a trademark of CrystalGraphics, Inc.

The PowerPoint PPT presentation: "MATLAB Programming" is the property of its rightful owner.

Do you have PowerPoint slides to share? If so, share your PPT presentation slides online with PowerShow.com. It's FREE!