Converting string scalar to written code
3 次查看(过去 30 天)
显示 更早的评论
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) ?
0 个评论
采纳的回答
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;"
writelines(str, 'testscript.m');
dbtype testscript.m
If you are wanting to write text into the middle of an existing file then unfortunately it gets a little more complicated.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 String Parsing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!