Chapter 4: Programming with MATLAB - FET
Chapter 4: Programming with MATLAB - FET Chapter 4: Programming with MATLAB - FET
Note the following rules when using for loops with the loop variable expression k = m:s:n • The step value s may be negative. Example: k = 10:-2:4 produces k = 10, 8, 6, 4. • If s is omitted, the step value defaults to 1. • If s is positive, the loop will not be executed if m is greater than n. • If s is negative, the loop will not be executed if m is less than n. • If m equals n, the loop will be executed only once. • If the step value s is not an integer, round-off errors can cause the loop to execute a different number of passes than intended. 4-25 Z.R.K
The continue Statement The following code uses a continue statement to avoid computing the logarithm of a negative number. x = [10,1000,-10,100]; y = NaN*x; for k = 1:length(x) if x(k) < 0 continue end y(k) = log10(x(k)); end y The result is y = 1, 3, NaN, 2. Z.R.K 4-26 More See pages 210-217.
- Page 1 and 2: UNIVERSITY OF JORDAN Faculty of Eng
- Page 3 and 4: 4-3 Components of an Algorithm •
- Page 5 and 6: 4-5 Steps for developing a computer
- Page 7 and 8: Effective documentation can be acco
- Page 9 and 10: Flowcharts are useful for developin
- Page 11 and 12: To locate a runtime errors, try the
- Page 13 and 14: Order of precedence for operator ty
- Page 15 and 16: Logical function ischar(A) isempty(
- Page 17 and 18: The if and else Statement The if st
- Page 19 and 20: Instead, consider what happens if w
- Page 21 and 22: For example, suppose that y = ln(x)
- Page 23 and 24: 4-22 Strings and the input Statemen
- Page 25: for Loops A simple example of a for
- Page 29 and 30: while Loops The while loop is used
- Page 31 and 32: 4-30 A simple example of a while lo
- Page 33 and 34: The switch Structure The switch str
- Page 35 and 36: The Editor/Debugger containing two
- Page 37: End of Chapter 4 Problems Page 241
Note the following rules when using for loops<br />
<strong>with</strong> the loop variable expression k = m:s:n<br />
• The step value s may be negative.<br />
Example: k = 10:-2:4 produces k = 10, 8, 6, 4.<br />
• If s is omitted, the step value defaults to 1.<br />
• If s is positive, the loop will not be executed if m is<br />
greater than n.<br />
• If s is negative, the loop will not be executed if m<br />
is less than n.<br />
• If m equals n, the loop will be executed only once.<br />
• If the step value s is not an integer, round-off<br />
errors can cause the loop to execute a different<br />
number of passes than intended.<br />
4-25<br />
Z.R.K