MATLAB PROGRAMMING FOR ENGINEERS
UPDATED ACTUAL QUESTIONS AND
CORRECT ANSWERS COMPLETE STUDY
GUIDE FULL SOLUTION
●● Top-down design approach
Answer: A method of programming that involves breaking a solution
into steps and further refining each one.
●● Generic algorithm
Answer: A modular program would consist of functions that implement
each step: 1. Get the input 2. Calculate result(s) 3. Display the result(s).
●● Scripts
Answer: Scripts are files in MATLAB that contain a sequence of
MATLAB instructions, implementing an algorithm.
●● Script execution
Answer: Once a script has been created and saved, it is executed by
entering its name at the prompt.
●● Type command
,Answer: The type command can be used to display a script in the
Command Window.
●● Documentation
Answer: Scripts should always be documented using comments.
●● Comments in MATLAB
Answer: Comments are used to describe what the script does, and how it
accomplishes its task; they are ignored by MATLAB.
●● H1 line
Answer: The first comment line in a script is called the 'H1 line'; it is
what is displayed with help.
●● Input function
Answer: The input function does two things: prompts the user, and reads
in a value.
●● Input for number
Answer: General form for reading in a number: variablename =
input('prompt').
●● Input for character
, Answer: General form for reading a character or character vector:
variablename = input('prompt', 's').
●● Output functions
Answer: There are two basic output functions: disp, which is a quick
way to display things, and fprintf, which allows formatting.
●● Format specifiers
Answer: The fprintf function uses format specifiers which include place
holders; these have conversion characters: %d integers, %f floats (real
numbers), %c single characters, %s string of characters.
●● Field width specification
Answer: Use %#x where # is an integer and x is the conversion character
to specify the field width of #.
●● Decimal places specification
Answer: %#.#x specifies a field width and the number of decimal places.
●● Newline character
Answer: \n is the newline character.
●● Tab character
UPDATED ACTUAL QUESTIONS AND
CORRECT ANSWERS COMPLETE STUDY
GUIDE FULL SOLUTION
●● Top-down design approach
Answer: A method of programming that involves breaking a solution
into steps and further refining each one.
●● Generic algorithm
Answer: A modular program would consist of functions that implement
each step: 1. Get the input 2. Calculate result(s) 3. Display the result(s).
●● Scripts
Answer: Scripts are files in MATLAB that contain a sequence of
MATLAB instructions, implementing an algorithm.
●● Script execution
Answer: Once a script has been created and saved, it is executed by
entering its name at the prompt.
●● Type command
,Answer: The type command can be used to display a script in the
Command Window.
●● Documentation
Answer: Scripts should always be documented using comments.
●● Comments in MATLAB
Answer: Comments are used to describe what the script does, and how it
accomplishes its task; they are ignored by MATLAB.
●● H1 line
Answer: The first comment line in a script is called the 'H1 line'; it is
what is displayed with help.
●● Input function
Answer: The input function does two things: prompts the user, and reads
in a value.
●● Input for number
Answer: General form for reading in a number: variablename =
input('prompt').
●● Input for character
, Answer: General form for reading a character or character vector:
variablename = input('prompt', 's').
●● Output functions
Answer: There are two basic output functions: disp, which is a quick
way to display things, and fprintf, which allows formatting.
●● Format specifiers
Answer: The fprintf function uses format specifiers which include place
holders; these have conversion characters: %d integers, %f floats (real
numbers), %c single characters, %s string of characters.
●● Field width specification
Answer: Use %#x where # is an integer and x is the conversion character
to specify the field width of #.
●● Decimal places specification
Answer: %#.#x specifies a field width and the number of decimal places.
●● Newline character
Answer: \n is the newline character.
●● Tab character