How can I execute a function if it exist, otherwise use a custom function?
knnsearch is a function from the "statistics and machine learning toolbox"
I created my own knnsearch, however, if the user has this function already I want to run it from the toolbox. if the user doesn’t have it, then execute my implementation.
The problem is that matlab fails in compiler time becasue it is expecting knnsearch to exist.
by the way… I used copilot and chatgpt for suggestions…. but their suggestions didn’t work.
function [k_idx, D] = knnsearch_lib(queryPoint, data, k)
% Check if the Toolbox knnsearch function is available
if exist(‘knnsearch’, ‘file’) == 2
[k_idx, D] = knnsearch(queryPoint, data, k);
else
% If not available, use custom implementation
[k_idx, D] = knn_custom(queryPoint, data, k);
end
endknnsearch is a function from the "statistics and machine learning toolbox"
I created my own knnsearch, however, if the user has this function already I want to run it from the toolbox. if the user doesn’t have it, then execute my implementation.
The problem is that matlab fails in compiler time becasue it is expecting knnsearch to exist.
by the way… I used copilot and chatgpt for suggestions…. but their suggestions didn’t work.
function [k_idx, D] = knnsearch_lib(queryPoint, data, k)
% Check if the Toolbox knnsearch function is available
if exist(‘knnsearch’, ‘file’) == 2
[k_idx, D] = knnsearch(queryPoint, data, k);
else
% If not available, use custom implementation
[k_idx, D] = knn_custom(queryPoint, data, k);
end
end knnsearch is a function from the "statistics and machine learning toolbox"
I created my own knnsearch, however, if the user has this function already I want to run it from the toolbox. if the user doesn’t have it, then execute my implementation.
The problem is that matlab fails in compiler time becasue it is expecting knnsearch to exist.
by the way… I used copilot and chatgpt for suggestions…. but their suggestions didn’t work.
function [k_idx, D] = knnsearch_lib(queryPoint, data, k)
% Check if the Toolbox knnsearch function is available
if exist(‘knnsearch’, ‘file’) == 2
[k_idx, D] = knnsearch(queryPoint, data, k);
else
% If not available, use custom implementation
[k_idx, D] = knn_custom(queryPoint, data, k);
end
end conditional dispatch MATLAB Answers — New Questions