Borrar filtros
Borrar filtros

Saving a cell array with structure in its rows

6 visualizaciones (últimos 30 días)
Rossi
Rossi el 13 de Feb. de 2022
Respondida: Image Analyst el 13 de Feb. de 2022
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

Respuestas (1)

Image Analyst
Image Analyst el 13 de Feb. de 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);

Categorías

Más información sobre Structures en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by