How do I call function with the same name from different toolbox?

51 visualizzazioni (ultimi 30 giorni)
I am trying to use the "tf" function that takes a digitalFilter object as the input and outputs the numerator and denominator vectors. However the control system toolbox tf function does the opposite.

Risposte (2)

Star Strider
Star Strider il 11 Giu 2020
Use the tf function from the Signal Ptocessing Toolbox:
lpFilt = designfilt('lowpassiir','FilterOrder',8, ...
'PassbandFrequency',35e3,'PassbandRipple',0.2, ...
'SampleRate',200e3); % Example From ‘designfilt’ Documentation
[num,den] = tf(lpFilt); % Transfer Function Polynomials
.

Image Analyst
Image Analyst il 11 Giu 2020
If you do
>> which -all functionName
and it shows several functions in different folders then MATLAB will take the top/first one. To see what functions you have that are overloaded, run my attached utility, what_is_overloaded.m.
If you want to run one that is second or lower on the list, you need to temporarily remove the path of the first one, then call your function, then restore the path of the first one.
rmpath(folder1); % Remove path of first functionName from search path.
% Now it will no longer see the first functionName, unless it's in the current folder.
functionName();
addpath(folder1); % Restore original folder.
I think you could also do it by changing directory to the folder of the one you want to run temporarily:
currentFolder = pwd; % Save original folder
cd(folderWhereFunctionNameLives); % Change to the folder of the functionName that you WANT to run lives.
% Now it will no longer see the first functionName, unless it's in the current folder.
functionName();
cd(currentFolder); % Restore original folder.
  8 Commenti
Walter Roberson
Walter Roberson il 9 Dic 2020
I also recommend using pathtool -- it gives a nice visual interface.
I have another same function in another directory, but it doesn't show up when I do 'which -all functionName'.
Functions in the current diretory always have priority over functions in any other directory when you call them by name. Therefore if you have a function (not a method) by the same name in your current directory, and in another directory, and you want to call the one in the other directory, you cannot do that directly.
What you can do is
curdir = cd('ThatOtherDirectory')
SomeVariableName = @NameOfFunction
cd(curdir);
after which
SomeVariableName(parameter, parameter, parameter...)
will invoke the one from that other directory, not the one from the current directory. Function handles remember the path to the file and use it when the function is called.
Fabrice Lambert
Fabrice Lambert il 2 Ott 2021
Is there any way to toggle the various functions in the help? For example, in my installation when I press F1 on "predict" it opens the Neural Network function. But what if I want to see the help for the linear model predict? Is there a shorter way than having to scroll through all the options in the documentation help?

Accedi per commentare.

Categorie

Scopri di più su Search Path in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by