keeping the variable names same

6 ビュー (過去 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 Center および File ExchangeEntering Commands についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by