When using fopen, what's the difference when we include/exclude 'w' in the second half of the parenthesis?

1 回表示 (過去 30 日間)
Jason
Jason 2013 年 11 月 23 日
回答済み: Harry MacDowel 2013 年 11 月 23 日
Suppose we want to open a file called exp.txt using fopen. What is the difference between these two code snippets:
fid = fopen('exp.txt', 'w');
fid = fopen('exp.txt');

回答 (1 件)

Harry MacDowel
Harry MacDowel 2013 年 11 月 23 日
The 'w' simply means write.
So if the file 'exp.txt' does not exist, that command will create exactly the file, and allows you to write to it.
If the file is already there, then it will overwrite the original content.
Without the 'w', Matlab just read the file, that's all.

カテゴリ

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