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

33 次查看(过去 30 天)
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.

回答(2 个)

Star Strider
Star Strider 2020-6-11
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 2020-6-11
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 个评论
Walter Roberson
Walter Roberson 2020-12-9
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 2021-10-2
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?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Install Products 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by