MATLAB: How to get Command Window format for existing ‘Cell Arrays’

cellcell array

I have a Cell-array created and i want to get the command window format for that cell-array.
For example: I have created a 5×2 cell array using command line:
MyCell = {'time' , 'timestamp';'posX', {'DePositionX', 'DePositionXmm'};'posY', {'DePositionY', 'DePositionYmm'};'velocityX', 'DeVelocityX';'velocityY', 'DeVelocityY'};
Similarly I have a MxN cell array already created(not by me) and i want to get the structure of that cell in a command window format as shown in the above code. Can you tell me is there any way or commands to get this.
Thanks.

Best Answer

You have a cell array and want to create the code, which produced this array. Right? Then try FEX: uneval .
If the elements of the cell are all strings or numbers, this would work also:
S = size(C);
fprintf('C = {');
for iR = 1:S(1)
for iC = 1:S(2)
data = C{iR, iC};
if ischar(data)
fprintf('''%s''', data);
elseif isnumeric(data)
fprintf('''%g''', data);
else
error('Class not supported.')
end
if iC < S(2)
fprintf(', ');
else
fprintf('...\n');
end
end
end
fprintf('};')