Writing Character Strings from Text file to CSV, Error using fprintf Function is not defined for 'cell' inputs
조회 수: 3 (최근 30일)
이전 댓글 표시
I'd like to have some code that will read in a column of strings from a text file, and print them in the first column of a CSV file. The following seems to read the file okay, but I'm getting an error about the fprintf function. I think I've indexed the cell array appropriately for this function, but maybe not. Can anyone tell what the issue might be? All of the character strings are of the same length and the format: S205_C1_S2_A1_D1_T051_VT.csv.
fid = fopen(file_name); C = textscan(fid, '%s'); fclose(fid);
fid1 = fopen('TrialNum_Output.csv','a');
for i = 1:length(C) fprintf(fid1,'%s\n',C{:}); %C{i} = {s(19:21)}; end
fclose(fid1);
댓글 수: 0
답변 (1개)
Sara
2015년 1월 14일
Use C = C{1} after the textscan command. But, why not using csvwrite later?
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Text Files에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!