File Exchange

image thumbnail

mat2colon

version 1.0.0.0 (1.99 KB) by Javier Lopez-Calderon
Converts a matrix (row x col) into a string using MATLAB colon notation (single resolution).

1 Download

Updated 18 Mar 2011

View License

Usage: strMat = mat2colon(Matrix, options)

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

Same as vect2colon but matrix capability

Example 1

mat2colon([14 12 10 8 6 4 2; 34 -23 0 1 45 46 47; 5 5 5 5 5 5 5])
ans =

[ 14:-2:2; 34 -23 0 1 45:47; 5 5 5 5 5 5 5]

Example 2

mat2colon([14 12 10 8 6 4 2; 34 -23 0 1 45 46 47; 5 5 5 5 5 5 5], 'Repeat', 'no')
ans =

{[ 14:-2:2];[ 34 -23 0 1 45:47];[ 5]}

See also: vect2colon, eval, str2num

Feedback is appreciated.

Cite As

Javier Lopez-Calderon (2021). mat2colon (https://www.mathworks.com/matlabcentral/fileexchange/30797-mat2colon), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (2)

Bruno Luong

I suggest to merge the two submissions mat2colon and vec2colon into one.

Javier Lopez-Calderon

I forgot to mention that mat2colon.m needs vect2colon.m in order to work. You can find it here http://www.mathworks.com/matlabcentral/fileexchange/22076

MATLAB Release Compatibility
Created with R2010a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!