keeping the variable names same

6 visualizaciones (últimos 30 días)
ali hassan
ali hassan el 25 de En. de 2022
Comentada: Walter Roberson el 25 de En. de 2022
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?

Respuesta aceptada

Walter Roberson
Walter Roberson el 25 de En. de 2022
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 comentarios
ali hassan
ali hassan el 25 de En. de 2022
instead of telling each option, we can just tell the desired change?
am i right
Walter Roberson
Walter Roberson el 25 de En. de 2022
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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Entering Commands en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by