frprintf into a file with adding the symbol for Single quote
조회 수: 55 (최근 30일)
이전 댓글 표시
Hello Everyone,
I have a textfile, which I created with matlab. Later, I want to use the text-file with a schme-macro in a simulation programm. I need every line in the textfile like this:
(define bla '(0 0 0 1 1 1)). The zeros and ones represent different possibilites.
My poroblem so far is, that I can't frpint the symbol ', due to the fact, that this symbol marks for matlab the end of the text in my code.
I am that far:
fid1 = fopen('test1.txt');
fid2 = fopen('test2.txt','w');
tline = fgets(fid1);
Character2add = '(define pyrx ('; % here put the character to be added
while ischar(tline)
disp(tline)
fprintf(fid2,'%s %s\n',Character2add,tline);
tline = fgets(fid1);
end
fclose(test1);
fclose(test);
What I got with this is:
'(define bla ('0 0 0 1 1 1
What I need now is:
- I need the last 2 paranthesis at the end of each line
- I need the single-quote symbol ' after my bla
댓글 수: 0
채택된 답변
Steven Lord
2021년 4월 29일
fprintf('There''s two main ways to print a single quote')
fprintf('Two single quotes '''' in a char format specifier prints a single quote '' in the result')
fprintf("Or if you're using a release that supports string, specify the format as a string")
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!