Usage: strvec = vect2colon(vec, options)
Converts a vector into a string using MATLAB colon notation (single resolution).
Options are:
'Delimiter' - 'on','yes','off','no' {default on} : Including square brackets []
(or curly brackets {} when output's dimensions are not consistent)
'auto' by default.
'Sort' - 'on','yes','off','no' {default off} : Sort elements in ascending order
'Class' - MATLAB classes
'Repeat' - 'on','yes','off','no' {default on} : Keep repeated elements
MATLAB colon notation is a compact way to refer to ranges of matrix elements.
It is often used in copy operations and in the creation of vectors and matrices.
Colon notation can be used to create a vector as follows
x = xbegin:dx:xend
or
x2 = xbegin:xend
where xbegin and xend are the range of values covered by elements of the x
vector, and dx is the (optional) increment. If dx is omitted a value of 1
(unit increment) is used. The numbers xbegin, dx, and xend need not be
integers.
Example 1:
>> x = [ 50 1000 1100 1200 2 3 4 5 6 10 20 30 40]
>> vect2colon(x)
ans =
[ 50 1000:100:1200 2:6 10:10:40]
or
>> vect2colon(x, 'Sort', 'on')
ans =
[ 2:6 10:10:50 1000:100:1200]
Example 2:
>> x = [ 2 3 4 5 6 10 10.1 10.2 10.3 10.4 1000 1100 1200]
>> s = vect2colon(x)
s =
[ 2:6 10:0.1:10.4 1000:100:1200 ]
Example 3:
>> x = [ 2 3 4 5 6 10 1000 1100 1200 10.1 10.2 10.3 10.4]
>> s = vect2colon(x, 'Delimiter', 'no')
s =
2:6 10 1000:100:1200 10.1:0.1:10.4
See also: mat2colon, eval, str2num
Feedback is appreciated. |