Using vecnorm function as defined in a toolbox
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I am using a toolbox called MNPBEM17, which includes a function called vecnorm. Its code is as follows:
function n = vecnorm( v, key )
% VECNORM - Norm of vector array.
%
% Usage :
% n = vecnorm( v )
% n = vecnorm( v, 'max' )
% Input
% v : vector array of size (:,3,siz)
% Output
% n : norm array of size (:,siz)
% or maximum of N if 'max' set
n = squeeze( sqrt( dot( abs( v ), abs( v ), 2 ) ) );
% maximum of N for 'max' keyword
if exist( 'key', 'var' ) && strcmp( key, 'max' ), n = max( n( : ) ); end
This function has the same name as a builtin function (https://nl.mathworks.com/help/matlab/ref/vecnorm.html) which works a little differently, but in any script I write, I want to use the version from the toolbox.
When launching Matlab 2019a I always get "Warning: Function vecnorm has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict." I don't want to change the name of the toolbox function though because I don't want to change any references to it throughout the toolbox. In Matlab 2019a, this is apparently not a problem and the toolbox function is always called:
v = rand(5,3);
a = squeeze( sqrt( dot( abs( v ), abs( v ), 2 ) ) )
b = vecnorm(v)
a =
0.8355
1.3565
1.1097
1.4095
1.4040
b =
0.8355
1.3565
1.1097
1.4095
1.4040
However, I recently installed Matlab 2021b and now it doesn't work that way. I put the toolbox at the top of the path. The commands "help vecnorm" and "open vecnorm" refer to the toolbox version, but the output of the same code as above is:
a =
0.8355
1.3565
1.1097
1.4095
1.4040
b =
1.6536 1.4947 1.6611
I deleted every file called vecnorm.* from the 2021b installation except the one from the toolbox. Still, the vecnorm function keeps giving me this undesired output.
Any ideas on how to persuade Matlab to use the vecnorm function from the toolbox?
6 Commenti
Risposte (2)
Matt J
il 8 Ott 2021
One solution I've found is to put vecnorm in a package directoy, e.g. +package/vecnorm.
If you then import the version of vecnorm from the package,
import package.vecnorm
then that version will be used (until you clear the import of course).
0 Commenti
Vedere anche
Categorie
Scopri di più su Linear Algebra in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!