How to fopen in this case?

4 ビュー (過去 30 日間)
dmfwlansejr
dmfwlansejr 2023 年 2 月 21 日
コメント済み: dmfwlansejr 2023 年 2 月 21 日
Hi Everybody
Case1
fid = fopen('TTL_1.txt', 'w');
fprintf(fid3,'%s \n','ABCD;');
fclose(fid3);
Case2
file_name='TTL_1';
fid = fopen('file_name.txt', 'w');
fprintf(fid3,'%s \n','ABCD;');
fclose(fid3);
Case1 is OK!
However, Case 2 does not create a file.
How to fopen in this case?
Thanks!

採用された回答

the cyclist
the cyclist 2023 年 2 月 21 日
You need to concatenate two character arrays, one of which you defined ahead ...
file_name='TTL_1';
fid = fopen([file_name,'.txt'], 'w');
  1 件のコメント
dmfwlansejr
dmfwlansejr 2023 年 2 月 21 日
Thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLow-Level File I/O についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by