varfun: how to get ride of the function name for the output variable?
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Xiaoyu Xu
el 8 de Dic. de 2019
Comentada: Xiaoyu Xu
el 9 de Dic. de 2019
When I apply varfun, the name of the function will show up in the returned variable name. For example, when I use
Strings = varfun(@string, x, 'inputvariables', 'Var1')
The returned variable name will be
string_Var1
My question is, is there a way to keep the original variable name instead of having ('string_') there?
0 comentarios
Respuesta aceptada
dpb
el 8 de Dic. de 2019
No. That's the way varfun is designed and works to keep from overwriting the original variable with the functional output having operated on the input variable(s). A table cannot have two columns with the same variable name and undoubtedly in most cases not overwriting the original variable would be the desired action--and certainly not being able to identify a new variable created from the original wouldn't be agoodthing™ when the new variable is something far different than the original.
I suppose it wouldn't harm anything to submit an enhancement request to have a way to cause that action, but I have my doubts TMW would see it as enough of a need as to have much likelihood at all of implementation.
That said, if you don't want the original variable any longer, you can delete it and then rename the functional column to that name; that can be done programmatically as the variables names are available from the xxx.Properties.VariableNames struct.
3 comentarios
dpb
el 9 de Dic. de 2019
Unless you rewrite the changed names back into the structure, nothing will change...
Strings.Properties.VariableNames=regexprep(Strings.Properties.VariableNames, 'string_', '');
Más respuestas (0)
Ver también
Categorías
Más información sobre Workspace Variables and MAT-Files en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!