"renamevars" doesn't return output
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I tried renaming a table variable, first without assigning the new table to a destination, then assigning to a destination:
>> x=[1;2;3]; y=[5;6;7]; z=table(x,y) % Create test table
z = 3×2 table
x y
_ _
1 5
2 6
3 7
>> renamevars(z,"x","xx") % Rename without assigning
Error using tabular/renamevars Using RENAMEVARS
without assigning to a workspace variable does not
modify the table's variable names. Use t =
renamevars(t,vars,newnames).
>> a=renamevars(z,"x","xx") % Rename with assigning
a = 3×2 table
xx y
__ _
1 5
2 6
3 7
Without assigning to a destination, "renamevars" actually errors out rather than issue a warning. I've always been able to view the result of an operation before assigning to a destination. To not support this seems extremely un-MATLAB-ish (and unlike most languages I've used) This is especially important when debugging in MATLAB, as one should not create objects that aren't already present in the code.
6 comentarios
Eric Sofen
el 18 de Nov. de 2022
Thanks for bringing this up. The renamevars behavior is consistent with categorical renamecats, but I agree it is inconsistent with other table behavior. I have an enhancement request to revise the renamevars behavior.
c = categorical(["a" "b" "c"])
renamecats(c,"a","z")
Respuestas (1)
Jan
el 8 de Nov. de 2022
If you want to change this behavior, login with admin privileges and modify the file renamevars.m. You find the check of nargout==0 on top.
As usual for modifying built-in functions: Strange side-effects might occur. Be careful and document the changes exhaustively. Remember that the changes might vanish during an update.
What about asking the MathWorks team for an explanation? Maybe this was a mistake only or there are some good reasons to avoid assigning ans utomatically.
Writing renamevars(z,"x","xx") instead of a=renamevars(z,"x","xx") saves 2 keystrokes. Is this useful?
3 comentarios
Jan
el 9 de Nov. de 2022
The MathWorks team does not scan the contents of the public forum. Writing a bug report or enhancement request is much better, because then the the information is forwarded directly to the support team.
A wrapper is an efficient idea also:
function Reply = myren(varargin)
Reply = renamevars(varargin{:});
end
Ver también
Categorías
Más información sobre Logical 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!