필터 지우기
필터 지우기

Saving a cell array with structure in its rows

조회 수: 4 (최근 30일)
Rossi
Rossi 2022년 2월 13일
답변: Image Analyst 2022년 2월 13일
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

답변 (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 = 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);

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by