Saving a cell array with structure in its rows

7 ビュー (過去 30 日間)
Rossi 2022 年 2 月 13 日
回答済み: Image Analyst 2022 年 2 月 13 日
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.)?

回答 (1 件)

Image Analyst
Image Analyst 2022 年 2 月 13 日
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 =; % 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.


Help Center および File ExchangeWhos についてさらに検索





Community Treasure Hunt

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

Start Hunting!

Translated by