When I was trying to convert to use fprintf to make a txt file, I came across the following code wile using docsearch to find more information. The code below works fine but I don't understand what the 'w' in the first line of code does. The only thing that I could discern was that the code will not work with it, but what is its specific function?
fileID=fopen('Example.txt','w');
fprintf(fileID,'%s %11s\n','title1','title2');
fprintf(fileID,'%u %13.3e\n',data');
type ('Example.txt')

댓글 수: 1

Stephen23
Stephen23 2015년 2월 16일
편집: Stephen23 2015년 2월 16일
Try reading through the fopen documentation. It is really useful for telling you what "function" different syntaxes have.

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

답변 (1개)

Geoff Hayes
Geoff Hayes 2015년 2월 16일

1 개 추천

Shengyi - the w is the file access type for the file that you are opening. In this case, the w indicates that you are opening a file for writing. If the file doesn't exist, a new one will be created. And if the file already exists, the current contents will be discarded.
See fopen input argument permissions for the different values that can be used when opening a file (for reading, writing, appending, etc.).

카테고리

도움말 센터File Exchange에서 Standard File Formats에 대해 자세히 알아보기

태그

질문:

2015년 2월 16일

편집:

2015년 2월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by