필터 지우기
필터 지우기

New line when writing to a text file using fprintf?

조회 수: 5 (최근 30일)
rman
rman 2022년 7월 13일
댓글: Star Strider 2022년 7월 13일
I would like to print to a .scad file to create a drawing on openscad.
I want to iterate the drawing through 1-8281. However, I want there to be 8282 seperate lines of code. For each seperate segment of drawing. For example, I want the code to print out:
1stline: $fn = 30
2ndline: {translate([1st,1st,0]);cylinder(1st,1st,1st);}
3rdline: {translate([2nd,2nd,0]);cylinder(2nd,2nd,2nd);}
4thline: {translate([3rd,3rd,0]);cylinder(3rd,3rd,3rd);}
8282ndline: {translate([8281st,8281st,0]);cylinder(8281st,8281st,8281st);}
i have attached my code here:
xm,ym,l2 and r2 are all 1x8281 arrays which i wish for their ith value to be printed out.
fo = fopen('random_lens.scad','wt')
fprintf(fo,'$fn = 30;');
for i=1:8281
fprintf(fo,'{translate([%d,%d,0]);cylinder(%d,%d,%d);}',xm(i),ym(i),l2(i),r2(i),r2(i));
end
fclose(fo);

채택된 답변

Star Strider
Star Strider 2022년 7월 13일
The newline character for fprintf and its friends is '\n', so perhaps:
fprintf(fo,'{translate([%d,%d,0]);cylinder(%d,%d,%d);}\n',xm(i),ym(i),l2(i),r2(i),r2(i));
.
  댓글 수: 2
rman
rman 2022년 7월 13일
you are a legend! thank you very much
Star Strider
Star Strider 2022년 7월 13일
As always, my pleasure!

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by