Graphics Programs Reference
In-Depth Information
>> v = sin((1:3)*pi/6)
v=
0.5000
0.8660
1.0000
>> num2str(v)
ans =
0.5 0.866031
>> q = reshape(1:9,3,3)
q=
1
4
7
2
5
8
3
6
9
>> int2str(q)
ans =
147
258
369
>> size(ans)
ans =
3
7
You can tell num2str how many digits to display by giving it a second
parameter:
>> num2str(pi,2)
ans =
3.1
>> num2str(pi,15)
ans =
3.14159265358979
The second parameter of num2str can also specify the format by means
of C language conversions. These involve the percent character, width
and precision fields, and conversion characters: d, f, e, etc. (see table
below). The basic idea is to use a string of characters beginning with %
to control the formatting. For example, to output five decimal places in
a field of 12 characters with exponential notation, use:
>> num2str(pi,'%12.5e')
ans =
3.14159e+00
>> num2str(-pi,'%12.5e')
ans =
-3.14159e+00
>> num2str(pi*1e100,'%12.5e')
Search WWH ::




Custom Search