Writting different length arrays in a CSV file

조회 수: 11 (최근 30일)
SS
SS 2017년 8월 19일
댓글: SS 2017년 8월 21일
Hi All,
I have one variable with 19 cell arrays consists of different lengths (such as 1*26,1*30 etc). Now, I want to save them in a CSV or XLS or any other text format. But, I don't know how to save them as they have different lengths. Please kindly let me know, if is it possible? Or If I have to append NaN at the end of the lower lengths array. If So, How Can do that?
Please kindly give an example as I am not good with cell arrays.
Thanks
  댓글 수: 2
Walter Roberson
Walter Roberson 2017년 8월 20일
Are they to be saved as individual lines, so one line of length 26, the second of length 30, and so on? And they are all row vectors?
SS
SS 2017년 8월 21일
Yes. They are all row vectors in different length.

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

채택된 답변

Walter Roberson
Walter Roberson 2017년 8월 20일
fid = fopen('YourOutputFile.txt', 'wt');
for K = 1 : length(YourCellArray)
this_row = YourCellArray{K}:
fprintf(fid, '%f,', this_row(1:end-1));
fprintf(fid, '%f\n', this_row(end) );
end
fclose(fid);

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by