Saving a cell array with structure in its rows
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponses (1)
Image Analyst
le 13 Fév 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);
0 commentaires
Voir également
Catégories
En savoir plus sur Structures dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!