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.
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.
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
fixed error when length(array)==1
Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.