Tuesday, February 17, 2009

MATLAB: vector to string conversion

To convert an vector to a string vect2str script by Luca Balbi from MATLAB Central File Exchange can be used. It works very good, but a little problem for me was that it works only with newer versions of MATLAB. For example it works in Matlab 7.4, but it does not work in Matlab 7.0. The reason is that it uses inputParser object, that is not available in version 7.0. For that reason I modified vect2str.m in such a way that instead of inputParse, getargs function is used (getargs is also available in this post).
Some example of how vect2str works:>> vect2str([1:5],'formatString','%.2f','separator','--')

ans =


>> vect2str([1:5],'formatString','%2d','separator',' -- ')

ans =

1 -- 2 -- 3 -- 4 -- 5

>> sprintf(vect2str([1:5],'formatString','%.2f','separator','\t'))

ans =

1.00 2.00 3.00 4.00 5.00

>> vect2str([1:5],'formatString','%.2f','separator','\t')

ans =




Scripts are here.

No comments:

Post a Comment