File Exchange

image thumbnail

array2string.zip

version 1.1 (2.85 KB) by

simple function that converts a cell array to a string.

2 Downloads

Updated

View License

string=array2string(array) converts a cell array to an evaluable string as used for example by eval(...). cells may contain strings, matrices, function handles and cells containing the aforementioned classes and other cells.

Comments and Ratings (2)

Jan Simon

Jan Simon (view profile)

You assume that the input is a 2D cell matrix, but this is not stated in the help section.
Creating the cell temp without a pre-allocation is slow. Better:
temp=reshape(array_loc', 1, []);
Checking for "length(temp)>1" in the IF condition is not needed: If temp is empty, the FOR loop body is not reached.
Please add to the help section, that SINGLE, LOGICAL, STRUCT and (U)INT8/16/32/64 data are ignored without a warning.
I'd expect that strings are enclosed in quotes. Otherwise the EVALing might lead to unexpected results. CHAR matrices let the function stop with an error.

Rob Aberg

Rob Aberg (view profile)

If you have Simulink installed, you can also use the built-in Simulink.saveVars command to save MATLAB variables including cell arrays, structs, and objects as executable MATLAB code in .m files. See the doc for more information: http://www.mathworks.com/help/toolbox/simulink/slref/simulink.savevars.html

Updates

1.1

fixed error when length(array)==1

MATLAB Release
MATLAB 7.10 (R2010a)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Win prizes and improve your MATLAB skills

Play today