In MatLab, "> help bi2de" provides the following example:
B = [0 0 1 1; 1 0 1 0];
D = bi2de(B)
But when I try this on my own, I get the following error:
??? Undefined function or method 'bi2de' for input arguments of type 'double'.
Is there something wrong with this function in MatLab?
I am pretty sure that the reason why this problem happened is because of the license of the toolbox, Communications system toolbook, in which this function belongs in. Write which bi2de and see what will be the result. If it returns path of the function and the comment Has no license available, then the problem is related to the license. That means, license of the toolbox is not set correctly. Mostly it happens if the toolbox is added later, i.e., after installation of the original matlab. Please check and solve the license issue, then it will work fine.
bi2de is a function in the Communications toolbox. You need to have that toolbox to use it. If you do have that toolbox, then the problem is that your B matrix is being treated as double instead of binary (I don't have the toolbox so I can't test this).
Consider using bin2dec, which turns a string representation ('1011001', eg) into a decimal number. This function is not part of a toolbox; it's available as part of the basic MATLAB package.
Related
I generate a call graph of a complex MATLAB system, and I want to know which functions are built-in and mark them.
Whether a function is built-in or not is most easily seen by the which command. For a given function name it displays the full path to the file that defines the function. For example, on my machine I see
>> which eig
built-in (/Applications/MATLAB_R2018b.app/toolbox/matlab/matfun/eig)
>> which solve
/Users/robert/Documents/MATLAB/cvx/lib/#cvxprob/solve.m % cvxprob method
>> which nosuchfunctionhere
'nosuchfunctionhere' not found.
telling me that eig is a built-in function, and solve a function that is part of the package cvx, and that nosuchfunctionhere is defined nowhere.
MATLAB makes a distinction between "built-in functions" (i.e. no M-file or MEX-file exists, the code is built into the MATLAB executable) and other functions that are part of the MATLAB package but written as M-files or MEX-files.
As Robert showed, the which function will tell you if a function is "built-in" or not, and it will give you a path.
For example, eig is a built-in function (the path given is a file containing the documentation):
>> p = which('eig')
p =
'built-in (/Applications/MATLAB_R2017a.app/toolbox/matlab/matfun/#single/eig)'
imshow is not built-in, but part of the core MATLAB toolbox:
>> p=which('imshow')
p =
'/Applications/MATLAB_R2017a.app/toolbox/matlab/images/imshow.m'
imdilate is a function that comes with the Image Processing Toolbox:
>> p = which('imdilate')
p =
'/Applications/MATLAB_R2017a.app/toolbox/images/images/imdilate.m'
and prettyplot is a function I wrote myself:
>> p = which('prettyplot')
p =
'/Users/cris/matlab/toolbox/cris/prettyplot.m'
To distinguish between these 4 cases, first check to see if the returned string begins with "built-in", then check to see if it contains fullfile(matlabroot,'toolbox','matlab'), indicating it is part of the core MATLAB toolbox, then check to see if it contains fullfile(matlabroot,'toolbox'), indicating it is part of another official toolbox:
function_name = 'eig';
p = which(function_name);
if startsWith(p,'built-in')
disp('built-in')
elseif contains(p,fullfile(matlabroot,'toolbox','matlab'))
disp('part of core MATLAB toolbox')
elseif contains(p,fullfile(matlabroot,'toolbox'))
disp('part of an official MATLAB toolbox')
else
disp('not an official MATLAB function')
end
However, do note that some functions could be overloaded! And if you're examining your source code to check which functions are being used, you need to know the types of the arguments passed. For example:
>> which -all eig
built-in (/Applications/MATLAB_R2017a.app/toolbox/matlab/matfun/#single/eig) % single method
built-in (/Applications/MATLAB_R2017a.app/toolbox/matlab/matfun/#double/eig) % double method
/Users/cris/newdip/target/dip/share/DIPimage/#dip_image/eig.m % dip_image method
Here you can see that there are three eig functions, one is used if its input argument is of type single, one if it is double, and one if it is dip_image (a custom class). Depending on the input, the function eig used is built-in or a 3rd party function.
The sad part is, you won't know which one is used until you run your code. You can manually check what values the input variables have, sometimes it is clear. But this is not always the case, the type might depend on data outside of the function you're examining.
So, the best way to collect a list of functions your program uses is to run the profiler.
Another alternative: the MATLAB Compiler (a separate product) will collect all source M-files your function uses, and package them together into a single distributable package.
Although I think solutions based on which are better, for completeness, we should also consider the function exist for this. From the documentation:
exist name returns the type of name as a number. This list describes the type associated with each value:
0 — name does not exist or cannot be found for other reasons. For example, if name exists in a restricted folder to which MATLAB® does not have access, exist returns 0.
1 — name is a variable in the workspace.
2 — name is a file with extension .m, .mlx, or .mlapp, or name is the name of a file with a non-registered file extension (.mat, .fig, .txt).
3 — name is a MEX-file on your MATLAB search path.
4 — name is a loaded Simulink® model or a Simulink model or library file on your MATLAB search path.
5 — name is a built-in MATLAB function. This does not include classes.
6 — name is a P-code file on your MATLAB search path.
7 — name is a folder.
8 — name is a class. (exist returns 0 for Java classes if you start MATLAB with the -nojvm option.)
So when we try this on the examples shown earlier:
>> exist eig
ans =
5
>> exist solve
ans =
2
>> exist nosuchfunction
ans =
0
Just type open followed by the function name in command window
open function_name
And function_name will be displayed into editor, you might see Mathwork copyright inside it if it's a build in function otherwise it's not
This is how the copyright looks
% Copyright 1993-2016 The MathWorks, Inc.
I'm using MATLAB 2015a. Even if I try to run document example of conv function, i get an error saying Error using conv (line 15), Not enough input arguments..
This is the example code I'm using:
u = [1 0 1];
v = [2 7];
w = conv(u,v)
What is the problem with my MATLAB?
It is hard to find the documentation for that version online without a license. You can find the documentation for your version by typing
help conv
Presumably the interface changed after your version. So you have to see what your documentation says.
FWIW, the documentation archives are here, but I cannot access them.
Also, I tried your code in Matlab 2015b (that is, b, not a), and it worked. So it must have changed between those two versions.
According to excaza, the docs haven't changed. So, like they say, it must be a shadowing issue. You would verify that by using clear all before your code snippet.
I tried using the .. command in MATLAB to generate Laguerre polynomials but I keep getting this error every time:
I found this in the help section:
Since I have defined x as symbolic I shouldn't be getting this error.
Also on website I found this which says that the function does not run in MATLAB.
Can anyone help? Thanks in advance
Like you say, and the matlab help says this function only works inside mupad, maybe in later versions it works in matlab console.
If you want to use it, write mupad in Matlab Command window and then use it in the mupad, matlab will return you the result as I show in the picture
In R2014b+, there is a laguerreL function available directly from within Matlab. However, a version of this function was introduced to MuPAD in R2009a. You can call the MuPAD version from within Matlab
syms x;
feval(symengine,'laguerreL',2,x)
or
evalin(symengine,'laguerreL(2,x)')
Both return x^2/2 - 2*x + 1.
You can read more about interacting with MuPAD functionality from Matlab here. However, I'd recommend browsing and searching the archived documentation for your specific version or using your built-in HTML documentation (e.g., doc mupad or doc 'calling mupad').
I have few continuous variables that look like this:
durs1=[3,40933 0,033630 0,25103 0,6361 0,71971 1,18311 1,91946 0,12842 0,97639 1,1383 0,46871 3,05241 2,34907 1,03788 0,76434 1,08798 1,462 0,4241 2,32128 0,29017..]
Each has more than 1000 values (all positive). I used
[a, b]=gamfit(durs1)
a =
2.3812 0.4200
b =
2.2316 0.3907
2.5408 0.4514
to find parameters of gamma distribution. Now I want to make a goodness of fit test in order to see how well the model fits my data. Matlab provides the one sample Kolmogorov-Smirnov test to solve the problem (http://www.mathworks.com/help/stats/kstest.html#btnyrvz-1)
But when I run my code (based on their examples):
test_cdf=makedist('Gamma','a',2.38,'b',0.42)
[h, p]=kstest(durs1,'CDF',test_cdf)
I have this error: "Undefined function 'makedist' for input arguments of type 'char'."
Can somebody help me to fix my code?
It seems like the function makedist of the statistics toolbox is available only from Matlab version r2013a. Looking in the documentation of earlier versions, even as late as r2012b, there is no mention of makedist. So I think updating to the latest version of matlab should solve your problem.
Using the adftest function in MATLAB's econometrics toolbox, I'm receiving the following error:
>> [h1,pVal1] = adftest(y1,'model','ARD')
Error using lagmatrix (line 25)
lagmatrix: wrong # of input arguments
Error in adftest>runReg (line 705)
yLags = lagmatrix(y,0:(testLags+1));
Error in adftest (line 417)
testReg = runReg(i,y,testT,testLags,testModel,needRegOut);
y1 is a <41x1> vector of doubles.
Has anyone received this error or have any thoughts on what the issue is? I am using this code right out of the box so I'm not sure what is going on. I'd post to MATLAB's site, but it is down for maintenance.
This is either a bug in Matlab, in which case you should submit it on the Matlab support site. Before you do that, you should check that you don't have a function lagmatrix on your path that shadows the built-in function. Type
which lagmatrix
on the command line. If the path does not point to your Matlab installation, you should move lagmatrix off the Matlab search path.
Also note that y1 should not contain all NaN, or be otherwise degenerate, so you may want to check the function using the sample data as suggested in the help to be sure it's a bug and not just your data.
I had the same problem with this function. In my case, the problem was the function lagmatrix (older version) in my MATLAB path and the adftest function was the newest version. The soluction was delete the older version of lagmatrix.