1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<TITLE>ONES Array of Ones
</TITLE>
</HEAD>
<BODY>
<H2>ONES Array of Ones
</H2>
<P>
Section: <A HREF=sec_array.html> Array Generation and Manipulations </A>
<H3>Usage</H3>
Creates an array of ones of the specified size. Two seperate
syntaxes are possible. The first syntax specifies the array
dimensions as a sequence of scalar dimensions:
<PRE>
y = ones(d1,d2,...,dn).
</PRE>
<P>
The resulting array has the given dimensions, and is filled with
all ones. The type of <code>y</code> is <code>float</code>, a 32-bit floating
point array. To get arrays of other types, use the typecast
functions (e.g., <code>uint8</code>, <code>int8</code>, etc.).
The second syntax specifies the array dimensions as a vector,
where each element in the vector specifies a dimension length:
<PRE>
y = ones([d1,d2,...,dn]).
</PRE>
<P>
This syntax is more convenient for calling <code>ones</code> using a
variable for the argument. In both cases, specifying only one
dimension results in a square matrix output.
<H3>Example</H3>
The following examples demonstrate generation of some arrays of ones
using the first form.
<PRE>
--> ones(2,3,2)
ans =
(:,:,1) =
1 1 1
1 1 1
(:,:,2) =
1 1 1
1 1 1
--> ones(1,3)
ans =
1 1 1
</PRE>
<P>
The same expressions, using the second form.
<PRE>
--> ones([2,6])
ans =
1 1 1 1 1 1
1 1 1 1 1 1
--> ones([1,3])
ans =
1 1 1
</PRE>
<P>
Finally, an example of using the type casting function <code>uint16</code> to generate an array of 16-bit unsigned integers with a value of 1.
<PRE>
--> uint16(ones(3))
ans =
1 1 1
1 1 1
1 1 1
</PRE>
<P>
</BODY>
</HTML>
|