Error message when writing file names with "\" character to text file.
    조회 수: 4 (최근 30일)
  
       이전 댓글 표시
    
I am outputting file names with partial paths, which have "\" in them, to a text file. If I only write the 12 character filename, I have no problem. It seems anything with a "\" yields an error (see attached).
% Write results to file outdata = [name(53:73),',',num2str(numberOfBlobs)]; fprintf(fid,outdata); fprintf(fid,'\r\n');
댓글 수: 0
채택된 답변
  Steven Lord
    
      
 2016년 12월 6일
        When you use the syntax fprintf(fid,outdata); the fprintf function is using your outdata variable as the format specification. Normally this is okay, if for example you wrote fprintf(fid, 'abcde') the char vector 'abcde' doesn't have any formatting operators. But if your char vector does contain something that looks like a formatting operator, like '\Z' for example, fprintf will try to treat it as a formatting operator. If it's not a formatting operator, you receive the warning you received.
In this case I recommend explicitly specifying a format specification like fprintf(fid, '%s', outdata). This way fprintf will interpret your outdata variable only as data, not as the format specification, and your data can include things that look like formatting operators without them being treated as formatting operators.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
				Help Center 및 File Exchange에서 Standard File Formats에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!