필터 지우기
필터 지우기

Converting string scalar to written code

조회 수: 3 (최근 30일)
Burçak
Burçak 2023년 12월 11일
댓글: Burçak 2023년 12월 12일
Is there a way to convert a string (suppose you have a variable str = "case 'newcase', x = 5; ") into written code in a script (not only to execute it) ?

채택된 답변

Walter Roberson
Walter Roberson 2023년 12월 12일
You can write text to a file using writelines() or by using fopen() / fprintf() / fclose(), or by using fopen() / fwrite() / fclose()
str = "case 'newcase', x = 5;"
str = "case 'newcase', x = 5;"
writelines(str, 'testscript.m');
dbtype testscript.m
1 case 'newcase', x = 5;
If you are wanting to write text into the middle of an existing file then unfortunately it gets a little more complicated.
  댓글 수: 1
Burçak
Burçak 2023년 12월 12일
Yes, actually I needed to write in the middle but definitely that's the way! Thanks

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 String Parsing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by