Modify built-in Matlab function without overwriting it
Mostrar comentarios más antiguos
For my current project I am using the insfilterNonholonomic object to fuse GNSS and IMU data. When looking at the code in detail (using the edit command), I realized that the motion model not only assumes motion without sideslip (as stated in documentation) but also no bouncing (not stated in documentation). I need a model that allows bouncing. This could be easily changed by removing one of the two velocity constraints (y and z direction), however I do not want to directly modify any built-in functions provided by Matlab since this will make it impossible to run the code on another computer. I am talking about adding two lines of code instead of having to re-write multiple thousand lines of code...
I understand that if I wanted to edit a simple function I could just save it under a different name and call it from my script using that name. However, the function that I need to change is called
correctKinematics(obj)
which is declared in the file NHConstrainedIMUGPSFuserBase.m on line 119 which is called in insfilterNonholonomic.m on line 371 using the command
obj@fusion.internal.NHConstrainedIMUGPSFuserBase(varargin{:});
I am using R2020b, I am not sure if maybe the line numbers changed in a newer release.
So how can I go about this if I don't want to rewrite all the code myself? Should I just manually copy all the involved files and "manually solve the dependencies"?
2 comentarios
dpb
el 10 de Nov. de 2021
That's by far the safest route, yes.
John D'Errico
el 10 de Nov. de 2021
Editing existing supplied code is a really, really bad idea. For any of the tools I have ever written, I always use the rule that if you change it, you own any problems that arise, in the sense that ANY problems that ever arise are now yours to deal with.
If you modify the code, then you want to make sure you modify it in a way that you copy and rename all such files, and then edit only your new versions. At least this way, if you trhen need to go back to the existing code, you can do so easily, and any others will not be surprised to see that code no longer works as expected.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Surrogate Optimization en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!