logo for matrixlab-examples.com
[?] Subscribe To This Site

XML RSS
Add to Google
Add to My Yahoo!
Add to My MSN
Subscribe with Bloglines


Home
Matrixmania Blog
Contact
-> Sitemap <-
Matlab Books
Quick Matlab Guide
Matlab Tutorials
Matlab Examples
Matlab Flow Control
Boolean Algebra
Linear Algebra
Matlab 2D Plots
Matlab 3D Plots
Matlab GUI
Matlab Cookbook I
Matlab Cookbook II
Probability and Stats
Forums and Help
Relevant Links
Fun!
Your own Website?
Terms/Policies
leftimage for matrixlab-examples.com

Matlab Code - Loops, branches, and control-flow



MATLAB code has its own instructions for control-flow statements like 'for-loops', 'while' and 'if-elseif' branching. Click on the links to see details and examples.

For loop
The for loop repeats a group of statements a fixed, predetermined number of
times. A matching end delineates the statements...

Application of Nested Iterations (Matrix Multiplication)
We show a script in Matlab code that performs a matrix multiplication step-by-step. The algorithm displays all the elements being considered for the multiplication and shows how the resulting matrix is being formed in each step. Obviously, Matlab can do it with just one operation, but...

While loop
The while loop repeats a group of statements an indefinite number of times
under control of a logical condition. A matching end closes the statements...

Square Root (using while-loops)
We’ll explore a square root algorithm as an excuse to use while-loops in our numerical software. We’re not going to use the built-in function ‘sqrt’...

If... elseif... else... end (branches or decisions)
The if statement evaluates a logical expression and executes a group of
statements when the expression is true. The optional elseif and else keywords provide for the execution of alternate groups of statements...

Break
The break statement lets you exit early from a for or while loop. In nested
loops, break exits from the innermost loop only...

Control Flow: for-loops, if-statements, break (in a Matrix Inversion)
This program performs the matrix inversion of a square matrix step-by-step. The inversion is performed by a modified Gauss-Jordan elimination method. We start with an arbitrary square matrix and a same-size identity matrix (all the elements along its diagonal are 1)...

Switch-Case-Otherwise
The switch statement executes groups of statements based on the value of a variable or expression. The keywords case and otherwise delineate the groups...

From 'Matlab Code' to home
To 'Matlab Examples'
Table of Contents

footer for matlab code page