Is there a way to define a new built-in function?

3 visualizaciones (últimos 30 días)
Yilmaz Baris Erkan
Yilmaz Baris Erkan el 8 de Feb. de 2021
Comentada: Yilmaz Baris Erkan el 9 de Feb. de 2021
Greetings,
For plotting purposes, I simply want to have a built-in function that gives you the color of your choice. Code is well written and ready, however, I wonder if there is a way to make it built-in instead of including the .m file where ever I need.
Any advice is most appreciated.
  2 comentarios
Matt J
Matt J el 8 de Feb. de 2021
What do you mean by "including the .m file wherever I need"? No matter what the implementation of the function is, it still has to be placed on the Matlab path so that Matlab can see it.
Stephen23
Stephen23 el 8 de Feb. de 2021
Editada: Stephen23 el 8 de Feb. de 2021
Put it on the MATLAB path (but definitely NOT in any installation folder or any application):

Iniciar sesión para comentar.

Respuesta aceptada

Matt J
Matt J el 8 de Feb. de 2021
Editada: Matt J el 8 de Feb. de 2021
I'm under the vague impression that you are unaware of the Matlab path and how it allows you to keep your mfiles in one place where Matlab can find them. See addpath and pathtool.
  4 comentarios
Stephen23
Stephen23 el 9 de Feb. de 2021
Editada: Stephen23 el 9 de Feb. de 2021
"I am asking if there is a way to eliminate this issue"
So far four people have told you to use the MATLAB Search Path, which you can define to include those folders. Have you tried doing that?
Note that in general it is better if data folders are not on the MATLAB Search Path, and you should read/write data files using absolute/relative filenames.
"(if making it a built-in function works, thats great)."
That is not the solution.
Yilmaz Baris Erkan
Yilmaz Baris Erkan el 9 de Feb. de 2021
@Matt J thank you for the guide and explanation. I appreciate it.

Iniciar sesión para comentar.

Más respuestas (2)

Fangjun Jiang
Fangjun Jiang el 8 de Feb. de 2021
I would think NO but it does not really make any difference. If there is a way, you would have to modify some existing files in the installation package or add some files to the installation foder, which is worse than adding the .m file to your custom folder, either for yourself use or for deploying to somebody else.
If you add your custom foder to the MATLAB path, you would not need to "include the .m file where ever I need". If you want to deploy to somebody else, you could also create the .p file to protect your algorithm.

John D'Errico
John D'Errico el 9 de Feb. de 2021
As others have said, you need to start using your MATLAB search path. Once you put a file in your own personal search path, it will be always accessible. Make sure you save the search path. You will use the tools addpath, savepath, pathtool, etc.
Be careful. Do NOT put your files in the MATLAB directories that came with MATLAB itself. Even if you have write permission in those directories, do not use those places to save your files. This is important. If you do not heed my warnings, then you ill find your files will not seem to have changes implemented in them when you modify your files. You would virtually be forced to quit and restart MATLAB to see any changes. (Or you would need to learn about the toolbox cache.)
A virtue of putting your files in you own separate directories is now when you upgrade MATLAB, all you need do is make sure the search path is also set with those directories on the path, and your files will become accessible to you in the new release.
All of this is NOT the same thing as making a function built-in, in the sense that it is now part of MATLAB itself. (You don't really want that anyway.) However, your files will be as accessible as if they were built-in.

Categorías

Más información sobre Search Path en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by