Graphics Programs Reference
In-Depth Information
The advantageofan in-linefunctionisthat itcan beembeddedinthe body of
the code;it does not havetoreside in an M-file.
1.6
Input/Output
Reading Input
The MATLAB function forreceiving user input is
value
= input('
prompt
')
It displays aprompt and then waits for input. If the input is an expression, it isevalu-
ated and returnedin
value
. The following twosamples illustrate the use of
input
:
>>a=input('Enterexpression:')
Enter expression: tan(0.15)
a=
0.1511
>>s=input('Enterstring:')
Enter string: 'Black sheep'
s=
Black sheep
Printing Output
As mentionedbefore, the result of a statement is printedif the statement does not end
with a semicolon. This is the easiest way of displaying results in MATLAB. Normally
MATLAB displays numerical results with about five digits, butthiscan bechanged
with the formatcommand:
format long
switches to 16-digit display
format short
switches to 5-digit display
To printformatted output, use the
fprintf
function:
fprintf('
format
',
list
)
where
format
containsformatting specifications and
list
is the list of itemstobe
printed,separatedbycommas. Typicallyused formatting specifications are
Search WWH ::
Custom Search