i found a usage of fopen which is not found in MATLAB documentations
here is my code
s = 'name';
fileID = fopen([s,'.txt'],'w');
this syntax really works. but i could not found the source.
the ordinary usage of fopen could be
fileID = fopen('name.txt','w')
why?
is MATLAB documentation uncomplete?
thank you!

댓글 수: 1

Stephen23
Stephen23 2020년 7월 13일
편집: Stephen23 2020년 7월 13일
"but i could not found the source."
Did you try reading the source that I gave in your earlier question?
"is MATLAB documentation uncomplete?"
No. Just because you combined several commands and could not find that specific combination of commands in the documentation does not mean that the documentation is "uncomplete". Lets try another example: here are some commands that I combined just now:
pow2(sqrt(mode([9,9,4,1])))
Will we find that combination in the MATLAB documentation? I very much doubt it. Does this mean that the MATLAB documentation is "uncomplete" ? No, it does not. It means the user needs to look up each of those commands separately, understand how they work, and undertand how the combination works. This is exactly the same for all programming languages.

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

 채택된 답변

madhan ravi
madhan ravi 2020년 7월 13일

0 개 추천

It’s not so complicated [] is used for concatenation
['name', '.txt'] % try it in command window and see what happens

댓글 수: 6

Walter Roberson
Walter Roberson 2020년 7월 13일
The syntax for fopen() is that the first parameter must be an expression that evaluates to a character vector or a scalar string object. 'name.txt' is an expression that evaluates to a character vector -- namely the one given right there in quotes. But [s, '.txt'] is also (potentially) an expression that evaluates to a character vector, but concatenating on '.txt' at the end of whatever s contains.
The syntax for fopen() does not require a literal quoted character vector giving an unchangable file name: you can use an expression of any sort, including a variable that holds the file name.
madhan ravi
madhan ravi 2020년 7월 13일
Thank you sir Walter , it’s profound explanation.
Stephen23
Stephen23 2020년 7월 13일
편집: Stephen23 2020년 7월 13일
"The syntax for fopen() does not require a literal quoted character vector..."
Are there any functions where a literal character vector is required? I cant imagine how this restriction would be useful, nor how the compiler would realistically enforce this.
Walter Roberson
Walter Roberson 2020년 7월 13일
Only for obtuse meanings of "required"
In the case of using command syntax instead of function syntax, then if an argument has whitespace or semi-colon or comma in it, then you need to use apostrophes (I seem to remember some cases where double-quotes did not do the trick, but I have not re-tested that in a couple of releases.)
jason lee
jason lee 2020년 7월 13일
yes, thank you all.
as Walter Roberson says '...including a variable that holds the file name.'
that's everything that i need.

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

추가 답변 (0개)

카테고리

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

제품

릴리스

R2019b

태그

질문:

2020년 7월 13일

댓글:

2020년 7월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by