Functions name duplication in toolbox

Hi,
I have a problem with function name duplication.
I am using a toolbox in which i have a function called "kmeans" ( a name that i dont want to change because it will lead to problems with other functions im working with), but there is a part in my program where i want to use matlab's implementation for the kmeans algorithem (https://www.mathworks.com/help/stats/kmeans.html#buefs04-X)
Is there any option to "sign" my program that i dont want to use the toolbox's kmeans but with the matlab's one?
Thanks

4 件のコメント

Deepak Gupta
Deepak Gupta 2021 年 10 月 27 日
You can try these answers:
https://www.mathworks.com/matlabcentral/answers/3167-two-functions-with-the-same-name-how-to-directly-call-one-of-both
Orr Streicher
Orr Streicher 2021 年 10 月 27 日
Hi, thanks for your response!
These answers are dealing with the case that you have the implementation of both function. In my case i have one function in a toolbox and the other one is built-in matalb function , so i dont think i can use the solutions mentions there.
Bjorn Gustavsson
Bjorn Gustavsson 2021 年 10 月 27 日
Why on Earth would you explicitly want to stick with a function-name that is the same as a built-in function - if your function is not some kind of fall-back option for users without the toolbox that supplies that Mathworks-supplied function?
Orr Streicher
Orr Streicher 2021 年 10 月 27 日
This toolbox has some features i want to use, but specificly with it's k-means implementation it looks like there is something wrong and i want to check it by using the built-in matlab function.
I agree that this is not very good working method, but this is a given situation that i try to find a solution to as simpe as possible, without leading to other problems in my program.

サインインしてコメントする。

回答 (1 件)

Jan
Jan 2021 年 10 月 27 日
編集済み: Jan 2021 年 10 月 28 日

0 投票

What about using builtin('kmeans') to call the Matlab version? [EDITED: This does not work. Thanks, Steven Lord]
Did you add your toolbox folders on top of Matlab's folders in the path? This is a bad idea.
Use packages if you really have the need to run different functions with the same name.

1 件のコメント

Steven Lord
Steven Lord 2021 年 10 月 27 日
kmeans is not a built-in function suitable for use with the builtin function. It is a MATLAB function file included as part of Statistics and Machine Learning Toolbox.
which kmeans
/MATLAB/toolbox/stats/stats/kmeans.m
builtin('kmeans', magic(10), 5)
Cannot find builtin function 'kmeans'

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeGet Started with MATLAB についてさらに検索

質問済み:

2021 年 10 月 27 日

編集済み:

Jan
2021 年 10 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by