Write multi-line strings into text file?
93 ビュー (過去 30 日間)
古いコメントを表示
Hi all,
I have a few lines of strings, which I'd like to write into a .inp (basically a text) file. The strings look like this:
>> strTest
strTest =
6×1 string array
"*Heading"
"** Job name: L2H1_dynamics Model name: Model-1"
"** Generated by: Abaqus/CAE 6.12-4"
"*Preprint, echo=NO, model=NO, history=NO, contact=NO"
"**"
"** PARTS"
I tried to use the following code to write it:
fid = fopen('strTestOtpt.inp', 'wt');
fprintf(fid, strTest);
fclose(fid);
got this error:
Error using fprintf
Invalid format.
I know I can probably use a loop to do this, but is there a better way? Many thanks!
0 件のコメント
採用された回答
その他の回答 (2 件)
Pawel Jastrzebski
2018 年 3 月 5 日
You're missing the format parameter of the 'fprintf' function:
fid = fopen('strTestOtpt.inp', 'wt');
formatSpec = '%s\n'
fprintf(fid, formatSpec, strTest);
fclose(fid);
0 件のコメント
Stephane
2021 年 2 月 12 日
You can use this oneliner to:
writematrix( strTest , 'strTestOtpt.inp' );
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!