vector to string

Converts a vector to a string, using the colon operator to represent linearly spaced subvectors.
660 Downloads
Updated 1 Feb 2010

View License

This is a small M-file that can be thought of as the inverse of the colon operator: it takes a linearly spaced row vector and generates a compact notation for that vector.
It handles concatenations of such vectors too, and will in fact for any real array (subject to considerations of numerical precision) generate a valid string representation of that array as a reshaped row vector.
I wrote this because I found myself using input dialog boxes in a GUI, where a numeric vector is entered as a string to be parsed by str2num, and I wanted to provide the current value of the vector as the default answer. mat2str already does this, but the result is unwieldy for all but the smallest arrays, so that was not really useful in this context.

Cite As

Sven Bossuyt (2024). vector to string (https://www.mathworks.com/matlabcentral/fileexchange/26453-vector-to-string), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2009b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes
1.2.0.0

generate error immediately if array is not numeric
changed logic of algorithm, to also handle NaN elements

1.1.0.0

* fixed bug where end of one subsequence is start of next one
* added spaces between subsequences, to improve readability
* changed behaviour for subsequences of length 2

1.0.0.0