how to store cell array in text file?

조회 수: 2 (최근 30일)
siddhesh rane
siddhesh rane 2013년 7월 25일
I have 496*6 cell array with strings in it i want to generate a text file can anyone tell how to do it?
I have elements in cell as shown below my cell array is as shown below..
'N1' 'G0' 'X0 'Y0' 'Z0' [] < -- row 1
'N1' 'G20' 'X30 'Y40' 'Z50' [] <--- row 2 upto 496 rows.
I m currenty using following code which is giving error
fileID = fopen('Gcode.txt','w');
fprintf(fileID,'%10s %10s %10s %10s %10s %10s \n', G_code{1,1}{:}, G_code{1,1} {:},G_code{1,1}{:},G_code{1,1}{:},G_code{1,1}{:},G_code{1,1}{:});
fclose(fileID);
  댓글 수: 2
Jan
Jan 2013년 7월 25일
편집: Jan 2013년 7월 25일
Please post the error message. Perhaps it reveals, why you try to access the elements of G_code as cells, although the description sounds, like they are strings.
Posting Matlab code, which create the input, is always better in a forum. Does this match your data:
C = {'N1', 'G0', 'X0', 'Y0', 'Z0', []; ...
'N1', 'G20', 'X30', 'Y40', 'Z50', []};
Are there some missing quotes in your example data behind X0 and X30?
siddhesh rane
siddhesh rane 2013년 7월 26일
Cell contents reference from a non-cell array object.
I m getting above error in fprintf lines.
G_code is a cell which has strings in it.

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

채택된 답변

Jan
Jan 2013년 7월 25일
편집: Jan 2013년 7월 25일
C = {'N1', 'G0', 'X0', 'Y0', 'Z0', []; ...
'N1', 'G20', 'X30', 'Y40', 'Z50', []};
D = C(:, 1:5).';
fileID = fopen('Gcode.txt','w');
fprintf(fileID, '%10s %10s %10s %10s %10s \n', D{:});
fclose(fileID);
If C does not match your input data, describe them again explicitly.
  댓글 수: 1
siddhesh rane
siddhesh rane 2013년 7월 26일
편집: siddhesh rane 2013년 7월 26일
Thank you !! its working.!!

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

추가 답변 (1개)

David Sanchez
David Sanchez 2013년 7월 26일
follow the link to the dlmcell.m file. It's a easy to use function to write cells to .txt file.
href = ""<http://www.mathworks.es/matlabcentral/fileexchange/?search_submit=fileexchange&query=dlmcell&term=dlmcell</a>>

카테고리

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

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by