
As you might have noticed, the output of our script is not displayed in a well-formatted fashion. Using disp, we can control how text or arrays are displayed in the command window. For example, to display a text string on the screen, type in disp('Hello world!'). This command will return our friendly greeting as follows: Hello world!
disp(variable) can be used to display only the value of a variable. To demonstrate this, issue the following command in the command window:
b = [1 2 3 4 5]
We have created a row vector with 5 elements. The following is displayed in the command window:
» b = [1 2 3 4 5]
b=
1 2 3 4 5
Now if we type in disp(b) and press enter, the variable name will not be displayed but its value will be printed on the screen:
» disp(b)
1 2 3 4 5
The following example demonstrates the usage of disp function.
- 瀏覽次數:1465