0

In the algorithm that I am dealing with, the nested cells are randomly generated in MATLAB. Consider this nested cell:

myCellArray ={2,2,1,1,{1,1,2,2,{1,2,{1,1,1,1,1}},2,2},{1,2,{1,2,2,2,2,2},2},{1,1},2,2,2,2,1,1,1,1,1};

The corresponding output of the cell is:

1×16 cell array Columns 1 through 13 {[2]} {[2]} {[1]} {[1]} {1×7 cell} {1×4 cell} {1×2 cell} {[2]} {[2]} {[2]} {[2]} {[1]} {[1]} Columns 14 through 16 {[1]} {[1]} {[1]}

Since the cell is generated randomly through an algorithm, I do not have access to the myCellArray in its original format (i.e., the way you write it as a command) written above. I must find a way to write the cell in its original command in a .txt file.

Please let me know if you have any suggestion or comment. Thank you.

Zander
  • 167
  • 1
  • 10
  • 1
    [This function](https://stackoverflow.com/a/38553646/2586922) I wrote some time ago seems to do exactly what you want. Note that arrays with more than 2 dimensions are not supported – Luis Mendo Jun 01 '18 at 22:05
  • 1
    Besides Luis' function, there are many similar ones on the [MATLAB File Exchange](https://www.mathworks.com/matlabcentral/fileexchange/?utf8=✓&term=cell2str). – Cris Luengo Jun 01 '18 at 22:31
  • 1
    Thanks, @LuisMendo. Your function is exactly what I was looking for. – Zander Jun 01 '18 at 22:37
  • 1
    Glad you found it helpful. Marking as duplicate then – Luis Mendo Jun 01 '18 at 22:39

0 Answers0