필터 지우기
필터 지우기

keeping the variable names same

조회 수: 2 (최근 30일)
ali hassan
ali hassan 2022년 1월 25일
댓글: Walter Roberson 2022년 1월 25일
i am importing a text file and keeping the variable header names same by using:
readtable('111..txt','PreserveVariableNames',true)
what is the function of true in this code?

채택된 답변

Walter Roberson
Walter Roberson 2022년 1월 25일
MATLAB uses Name/Value pairs in which the first element of the pair tells the option name and the second element of the pair indicates the state to use.
MATLAB does not use option keywords (that force behaviour if they appear by themselves). Keyword options are harder to parse. If you use name/value pairs consistently then each routine can parse for the options it is interested in and can ignore the other options; but if you permit keyword options that take effect just by appearing alone, then every parsing routine that deals with those options would have to know the complete list of keyword options so it would know whether to advance by one or two positions to keep looking for more options.
So, 'PreserveVariableNames', true means that names are to be preserved, and 'PreserveVariableNames', false would mean that names are not to be preserved (which is currently the default.)
  댓글 수: 2
ali hassan
ali hassan 2022년 1월 25일
instead of telling each option, we can just tell the desired change?
am i right
Walter Roberson
Walter Roberson 2022년 1월 25일
You must pass each option that you want to have different than the default.
It is not necessary to pass in options that will match the default value -- however, it can be useful to do so as a form of documentation. For example, when-ever I open a serial port, I explicitly set the port speed instead of relying on the default, because doing that saves me and the readers from having to search the documentation to find out what the default is in that situation.
Also, explicitly passing an option can be useful in reducing the amount of work to switch between values. For example if I think I might be switching back and forth between PreserveVariableNames true or false, then it is easier to write in the option and whatever the current value is, and then I only have to switch between true and false in the code, instead of having to delete the option each time I happen to want the behaviour that matches the default and re-enter it each time that I want a different behaviour.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by