UpTo

UpTo[n]

is a symbolic specification that represents up to n objects or positions. If n objects or positions are available, all are used. If fewer are available, only those available are used.

Examples

open allclose all

Basic Examples  (7)

Take up to the number of elements available:

Drop up to the number of elements available:

Take up to the number of elements available, dropping what remains, if anything:

Partition into blocks that are up to 3 elements long; the last block is shorter:

Give the 10 most common elements, or as many as are available:

Give the order of the 10 smallest elements, or as many as are available:

Give the maximum height and width of a graphic:

Scope  (7)

Take up to 20 characters from a string:

Find the 4 largest eigenvalues in a matrix, or as many as there are if fewer:

Create a "ragged" partition where last elements can be shorter:

Obtain the 6 most common elements, or as many as there are if fewer:

Generate a random sample of up to 6 elements, or as many as there are if fewer:

Obtain the first 4 minimal elements, or as many as are available:

Partition an image so that lengths are up to 36 pixels and heights are up to 28 pixels:

Properties & Relations  (2)

Cases behaves as though it implicitly uses UpTo:

You can give an explicit UpTo specification to Cases:

ImageTake behaves as though it implicitly uses UpTo:

You can give an explicit UpTo specification to ImageTake:

Introduced in 2015
 (10.3)