0% found this document useful (0 votes)
56 views

Matlab Programming Control Structures

Matlab is a programming language with the same basic control structures that are available in every other programming language. This document shows examples of these structures in action.

Uploaded by

Luthfi
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views

Matlab Programming Control Structures

Matlab is a programming language with the same basic control structures that are available in every other programming language. This document shows examples of these structures in action.

Uploaded by

Luthfi
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Matlab programming control structures - if-else, for and while

Matlab is a programming language with the same basic control structures that are available in every other programming language. This document shows examples of these structures in action. Contents if-else while for if-else example 1
a = 2; b = 76; if (a < 1 || (a > 1 && b < 80)) disp('Condition is true') else disp('Condition is false'); end Condition is true

Example 2
a = 83; b = 89; if (a < 50) disp('a elseif (b > disp('b else disp('a end

is less than 50') 1000) is greater than 1000 and a is not less than 50'); is not less than 50 and b is not greater than 1000');

a is not less than 50 and b is not greater than 1000

while Example 1
k = 0; while (k < 4) disp(k) disp('Looping'); k = k + 1; end 0 Looping 1 Looping 2 Looping 3

Looping

for
x = [-9 4 2 4 56 6]; for k = 1 : 4 disp(x(k)) end -9 4 2 4 x = [-9 4 2 4 56 6]; for k = 1 : length(x) disp(x(k)) end -9 4 2 4 56 6 for k = 1: 2 : length(x) disp(x(k)) end -9 2 56

Published with MATLAB 7.0

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy