Saving a cell array with structure in its rows

4 views (last 30 days)
Hi,
I have a cell array of size 500*1 cell. In each of its rows, I have 1*1 structure that has two fields. One field is of character type and the other is of cell type. I would like to have the whole information saved in a single file. Is there any way that I can do it in any non .mat format (.csv, .txt, etc.)?
Thanks

Answers (1)

Image Analyst
Image Analyst on 13 Feb 2022
You could do a loop over all cells, then extract the contents and use fprintf(). Here is a start
fid = fopen('output.txt', 'wt');
for k = 1 : length(ca)
thisCell = ca{k}; % Get contents of this one cell. Returns a structure
% Get the character string
fprintf(fid, '%s\n', thisCell.stringVariable); % Or whatever you called your string variable.
% Get the sub-cell
subCell = thisCell.ca; % Or whatever the cell array is called.
subCellContents = subCell{1};
% Now use fprintf to write out subCellContents into the file.
% How you do that depends on what's in that cell.
end
fclose(fid);

Categories

Find more on Cell Arrays in Help Center and File Exchange

Tags

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!