Concatenation of nested cell in one array and writing in text file

조회 수: 6 (최근 30일)
Nazar Adamchuk
Nazar Adamchuk 2021년 4월 26일
편집: Jan 2021년 4월 26일
How do I rearrange a 8x1 nested cell into one long cell array (variable attached). Each (from 8) cell includes 2x1 cell. My goal is twofold:
  1. saving the of the 8x1 nested cell in a cell array
  2. writing the unnested cell array to a text file
Thanks!

채택된 답변

Jan
Jan 2021년 4월 26일
Data = load('nestedCell.mat');
C = cat(2, Data.nestedCell{:});
FID = fopen('YourFile.txt', 'w');
fprintf(FID, '%-8s%g\n', C{:});
fclose(FID)
  댓글 수: 2
Nazar Adamchuk
Nazar Adamchuk 2021년 4월 26일
fprintf(FID, '%-8s%g\n', C{:});
I understood everything except this part: '%-8s%g\n'. What does 8 mean? If it means the number of cells in the original nested array, how I can change my code in case if do not know how many cells the nested array conatins.
Jan
Jan 2021년 4월 26일
편집: Jan 2021년 4월 26일
Try it:
fprintf('*%-8s*\n', 'asd')
*asd *
fprintf('*%8s*\n', 'asd')
* asd*
The 8 is the number of chars reserved for the output. With - the string is moved to the left, without - to the right. So this is only to have a nice formatted output. See:
doc fprintf

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by