Chapter 4: Programming with MATLAB - FET
Chapter 4: Programming with MATLAB - FET Chapter 4: Programming with MATLAB - FET
Strings and Conditional Statements The following prompt program is a script file that allows the user to answer Yes by typing either Y or y or by pressing the Enter key. Any other response is treated as the answer No. response = input(’Want to ... continue Y/N [Y]: ’,’s’); if(isempty(response))|(response==’Y’)... |(response==’y’) response = ’Y’ else response = ’N’ end Z.R.K 4-23 More See pages 209-210.
for Loops A simple example of a for loop is for k = 5:10:35 x = k^2 end The loop variable k is initially assigned the value 5, and x is calculated from x = k^2. Each successive pass through the loop increments k by 10 and calculates x until k exceeds 35. Thus k takes on the values 5, 15, 25, and 35, and x takes on the values 25, 225, 625, and 1225. The program then continues to execute any statements following the end statement. 4-24 Z.R.K Flowchart of a for Loop. Figure 4.5–1
- 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: 4-22 Strings and the input Statemen
- Page 27 and 28: The continue Statement The followin
- 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
Strings and Conditional Statements<br />
The following prompt program is a script file that allows the<br />
user to answer Yes by typing either Y or y or by pressing the<br />
Enter key. Any other response is treated as the answer No.<br />
response = input(’Want to ...<br />
continue Y/N [Y]: ’,’s’);<br />
if(isempty(response))|(response==’Y’)...<br />
|(response==’y’)<br />
response = ’Y’<br />
else<br />
response = ’N’<br />
end<br />
Z.R.K<br />
4-23 More See pages 209-210.