Difference between revisions of "Concat"

m
Line 2: Line 2:
 
[[Category:Doc Status D]] <!-- For Lumina use, do not change -->
 
[[Category:Doc Status D]] <!-- For Lumina use, do not change -->
  
= Concat(A,B'',I,J,K'') =
+
== Concat(a, b'', i, j, k'') ==
  
Concatenates lists or arrays.
+
Concatenates two lists or arrays to create a single list or array with a longer index.
  
 
When A and B are 1-D arrays,
 
When A and B are 1-D arrays,
  Concat(A,B)
+
  Concat(A, B)
returns a list (1-D array) consisting of their elements.  This form is often used to concatentate two indexes to obtain the elements for a third index.
+
returns a list (1-D array) consisting of their elements.  This form is useful to concatenate two indexes to generate a third index.
  
 
When A and B are 1-D arrays with a common index
 
When A and B are 1-D arrays with a common index
  
  Concat([A],[B])
+
  Concat([A], [B])
returns a 2-D array with two columns.  Notice square brackets surrounding the variables.  If only two parameters are used, column index is .K.   
+
returns a 2-D array with two columns.  Notice the square brackets around each variable.  If only two parameters are used, column index is .K.   
  
When A and B are arbitrary arrays, where A has index I and B has index J, then
+
When A is an array with index I and B is an array with index J,
  Concat(A,B,I,J,K)
+
  Concat(A, B, I, J)
concatenates (i.e., joins) arrays A and B, with the new result indexed by K. You must provide an index K whose length is the sum of the lengths of I and J.  Often the index K is obtained using the first form of concatenate.
+
concatenates (i.e., joins) arrays A and B, with the new result indexed by local index .K  whose values are the concatenation of I and J.
  
''(new to 4.1)'' You can omit the K parameter:
+
Or you can provide the index K for the result, whose length must be the sum of the lengths of I and J:  
  Concat(A,B,I,J)
+
  Concat(A, B, I, J, K)
when you do so, the function creates a new local index named K for the result.
+
When using this five parameter form, the index values of I and J are ignored --  so it doesn't matter if the elements of <code>K</code> are also elements of <code>I</code> or J. All that matters is that the number of elements in <code>K</code> is the number of elements of <code>I</code> plus the number of elements in <code>J</code>.  The positional ordering of the slices of each array are not altered -- the result consists of all the elements of <code>A</code> followed by all the elements of <code>B</code>.  
 
 
When using the five parameter form, <code>Concat(A,B,I,J,K)</code>, the index element values don't impact the result, so it doesn't matter if the elements of <code>K</code> are also elements of <code>I</code> or <code>J</code>, nor does it matter what order the index elements of <code>K</code> appear in. All that matters is that the number of elements in <code>K</code> is the number of elements of <code>I</code> plus the number of elements in <code>J</code>.  The positional ordering of the slices of each array are not altered -- the result consists of all the elements of <code>A</code> followed by all the elements of <code>B</code>.  
 
  
 
When <code>A</code> (or <code>B</code>) is implicitly indexed (for example, if it is a list or a single number), you can omit the index parameter.  For example:
 
When <code>A</code> (or <code>B</code>) is implicitly indexed (for example, if it is a list or a single number), you can omit the index parameter.  For example:
  Concat([0],B,,J,K)
+
  Concat([0], B, , J)
would prepend a column of zeroes to <code>B</code>.
+
prepends a column of zeroes to <code>B</code>.
 
 
= Library =
 
 
 
Array functions
 
  
= Examples  =
+
== Examples  ==
  
  Index In1&nbsp;:= ['a','b','c']
+
  Index In1&nbsp;:= ['a', 'b', 'c']
  
  Concat( In1, ['z'] ) &amp;rarry ['a','b','c','z']
+
  Concat(In1, ['z']) &amp;rarr; ['a', 'b', 'c', 'z']
  
  index I&nbsp;:= [1, 2];
+
  INDEX I&nbsp;:= [1, 2];
  index J&nbsp;:= ['a', 'b'];
+
  INDEX J&nbsp;:= ['a', 'b'];
  index K&nbsp;:= concat(J, 'c');
+
  INDEX K&nbsp;:= Concat(J, 'c');
  var A&nbsp;:= Array( I, J, 1 );
+
  VAR A&nbsp;:= Array( I, J, 1 );
  var B&nbsp;:= Array( I, 2 );
+
  VAR B&nbsp;:= Array( I, 2 );
 
  Concat( A, [B], J, , K)
 
  Concat( A, [B], J, , K)
 
   
 
   
Line 51: Line 45:
 
  2|  1, 1, 2]
 
  2|  1, 1, 2]
  
= See Also =
+
== See Also ==
  
 
* [[ConcatRows]]
 
* [[ConcatRows]]
 
* [[ConcatN]]
 
* [[ConcatN]]

Revision as of 02:41, 11 September 2015


Concat(a, b, i, j, k)

Concatenates two lists or arrays to create a single list or array with a longer index.

When A and B are 1-D arrays,

Concat(A, B)

returns a list (1-D array) consisting of their elements. This form is useful to concatenate two indexes to generate a third index.

When A and B are 1-D arrays with a common index

Concat([A], [B])

returns a 2-D array with two columns. Notice the square brackets around each variable. If only two parameters are used, column index is .K.

When A is an array with index I and B is an array with index J,

Concat(A, B, I, J)

concatenates (i.e., joins) arrays A and B, with the new result indexed by local index .K whose values are the concatenation of I and J.

Or you can provide the index K for the result, whose length must be the sum of the lengths of I and J:

Concat(A, B, I, J, K)

When using this five parameter form, the index values of I and J are ignored -- so it doesn't matter if the elements of K are also elements of I or J. All that matters is that the number of elements in K is the number of elements of I plus the number of elements in J. The positional ordering of the slices of each array are not altered -- the result consists of all the elements of A followed by all the elements of B.

When A (or B) is implicitly indexed (for example, if it is a list or a single number), you can omit the index parameter. For example:

Concat([0], B, , J)

prepends a column of zeroes to B.

Examples

Index In1 := ['a', 'b', 'c']
Concat(In1, ['z']) &rarr; ['a', 'b', 'c', 'z']
INDEX I := [1, 2];
INDEX J := ['a', 'b'];
INDEX K := Concat(J, 'c');
VAR A := Array( I, J, 1 );
VAR B := Array( I, 2 );
Concat( A, [B], J, , K)

Result:
   a  b  c
1| [1, 1, 2
2|  1, 1, 2]

See Also

Comments


You are not allowed to post comments.