필터 지우기
필터 지우기

Alternative to writecell?

조회 수: 42 (최근 30일)
L'O.G.
L'O.G. 2022년 4월 2일
댓글: Walter Roberson 2022년 4월 2일
The function writecell was introduced in R2019a to write the contents of a cell array to a file. What would be the previous way to do the following?
writecell(C,'C_data.csv')
For me, each cell element has either a number or []. All of the entries in row 1 are numbers. In newer versions of MATLAB, writecell is really nice for this because I am able to generate the .csv file with just the numbers, even though each column is a different length. I would like to know another way to do this.
  댓글 수: 1
Walter Roberson
Walter Roberson 2022년 4월 2일
It is not obvious why you have editted your question twice but not responded to my answer?

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

채택된 답변

Walter Roberson
Walter Roberson 2022년 4월 2일
xlswrite() can write cell arrays in which each cell entry contains a single element; however "The xlswrite function does not support writing cell arrays that contain different data types when attempting to write CSV files."
I am not certain at the moment whether it would be able to support writing [] to csv .
If you need csv with emptyiness for [] (or for nan) then you might need to resort to using fopen() and writing the lines as text. For example,
fmt = [repmat('%g,', 1, 14), '%g\n'];
fid = fopen(TheFIlename, 'wt');
for K = 1 : size(TheCell, 1)
fprintf(fid, fmt, TheCell{K,:})
end
fclose(fid)
If entries in TheCell are [] then this would leave entries such as "3,,5' with nothing between the spaces.
If you wanted to trim away trailing empty cells then that would take more work but could be done.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by