Matlab function area() not working - matlab

The in-build matlab function area() stopped working.
I tried to run the example from the documentation:
Y = [1, 5, 3;
3, 2, 7;
1, 5, 3;
2, 6, 1];
figure
area(Y)
but I would get the error message
Error using area (line 35)
Too many input arguments.
I am using 8.5.0.197613 (R2015a).

This CW answer was created to indicate that this question was resolved.
This turned out to be an issue related to the MATLAB search path. Using restoredefaultpath resolved it.
A symptom of this problem can appear when running which -all <function name> (without the <>), and getting back a list with unexpected entries.
From the documentation of which:
The results are ordered according to the Function Precedence Order, unless they are shadowed. Among shadowed results, you should not rely on the order of the functions and methods in str. To determine if a result is shadowed, call which without specifying an output. which indicates shadowed results by the comment, % Shadowed.

Related

Why MATLAB returns an error using `conv` function?

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.

What does a function with this ~ mean? (e.g. function=f(~, x, y))

I am doing another coursera assignemnt, this time with aerial robotics. I have to program a pd controller using the matlab ode45 (ordinary diff. equation). And the file that has to contain this code gets called as follows:
pd_controller(~, s, s_des, params)
I searched around but couldn't find anthing that explain this to me and how it works.
In the main program the function is called with a time variable which I would need for my ODE:
controlhandle(t, s, s_des, params)
Where this controlhandle is the functionhandler for pd_controller.
So, what does this mean? And can I access whatever is behind ~?
Besides:
I found one example, but the other around. A function, let's call it function = f(a,b) was called with f(~, b) where a and b has been declared inside the function.
The symbol is called a tilde, and it signifies that you are ignoring that input argument.
See the documentation here: https://mathworks.com/help/matlab/matlab_prog/ignore-function-inputs.html
In your case, the function controlhandle will not be passed a t variable, and probably has (should have) some check for this and perhaps a default t if none is given.
This works the same with output arguments, for example if you want the index of a max in an array, but not the max itself, you would use
a = [pi, 3.6, 1];
[~, idx] = max(a); % idx = 2, we don't know what the max value is
It means you don't need pass this parameter in this function call. Also, you can use it in the output of some functions too. For example:
A = [1 4 2 2 41];
[~, B] = sort(A);
this means you don't need the second output, and you can ignore that.
In your case, when no value sent for the first parameter t, probably the function acts on a default value for t in his computation.
Also, you can find more about that in matlab documentation.
I should have mentioned that this post exists as an answer, but it might be here instead.

Popup value in Simulink Mask doesn't refresh

I am currently masking a block in simulink.
The mask contains a popup list called dbclist with hardcoded type options (1, 2, 3, ..., 7).
The callback function of said popup list looks like this:
msk = Simulink.Mask.get(gcb);
dbcPopup = msk.getParameter('dbclist');
dbcPopup.Value
When changing the value of dbclist while using the mask the command window always responds with:
ans =
1
ans =
1
ans =
1
How can I get the actual value of dbclist?
I am using MATLAB 2014b on Mac OS X.
As stated here (http://de.mathworks.com/matlabcentral/answers/290286-popup-value-in-simulink-mask-doesn-t-refresh) I have found another way to get the actual value of my popuplist. I still don't know what is wrong with the first approach. If anyone figures out where the error is I would really appreciate telling me.

Converting a matlab script into python

I'm an undergrad at university particapting in a research credit with a professor, so this is pretty much an independent project for me.
I am converting a matlab script into a python (3.4) script for easier use on the rest of my project. The 'find' function is employed in the script, like so:
keyindx = find(summags>=cumthresh,1)
Keyindx would contain the location of the first value inside summag above cumthresh
So, as an example:
summags = [ 1 4 8 16 19]
cumthresh = 5
then keyindx would return with an index of 2, whose element corresponds to 8.
My question is, I am trying to find a similar function in python (I am also using numpy and can use whatever library I need) that will work the same way. I mean, coming from a background in C I know how to get everything I need, but I figure there's a better way to do this then just write some C style code.
So, any hints about where to look in the python docs and about finding useful functions in general?
A quick search led me to the argwhere function which you can combine with [0] to get the first index satisfying your condition. For example,
>> import numpy as np
>> x = np.array(range(1,10))
>> np.argwhere(x > 5)[0]
array([5])
This isn't quite the same as saying
find(x > 5, 1)
in MATLAB, since the Python code will throw an IndexError if none of the values satisfy your condition (whereas MATLAB returns an empty array). However, you can catch this and deal with it appropriately, for example
try:
ind = np.argwhere(x > 5)[0]
except IndexError:
ind = np.array([1])
np.nonzero(x) gives a tuple of the nonzero indices. That value can then be used to index any array of the matching size.
In [1262]: x=np.arange(6).reshape(2,3)
In [1263]: ind=np.nonzero(x>3)
In [1264]: x[ind]
Out[1264]: array([4, 5])
In [1265]: ind
Out[1265]: (array([1, 1], dtype=int32), array([1, 2], dtype=int32))

Issue with assigning output from a function in MATLAB

I am having problem when I try to store rmabackadj function's output to a variable. The function works properly when no output variable is assigned. This function is part of bioinformatics toolbox.
So the issue is when I try to run the following it works properly:
rmabackadj(myprobeData.PMIntensities)
But when I try to run the following I get an error:
>> A = rmabackadj(myprobeData.PMIntensities)
Warning: Colon operands must be real scalars.
> In rmabackadj>findMaxDensity at 255
In rmabackadj at 164
Error using ksdensity>parse_args (line 162)
X must be a non-empty vector.
Error in ksdensity (line 114)
[axarg,yData,n,ymin,ymax,xispecified,xi,u,m,kernelname,...
Error in rmabackadj>findMaxDensity (line 255)
[f, x] = ksdensity(z, min(z):(max(z)-min(z))/npoints:max(z), 'kernel', 'epanechnikov');
Error in rmabackadj (line 164)
mu = findMaxDensity( o(o < mu));
I searched for it online as well, but I couldn't find any result. Does anybody have any idea about the cause of this error?
PS: When I assign ans variable to a new variable, it is properly assigned.
A = ans
I'm pretty sure this is a bug.
Firstly, the reason it errors only when you supply an output argument is because there's an internal switch in the function that calculates different things based on nargout. That's an odd design, but not necessarily a bug.
Internal to rmabackadj there are two subfunctions findMaxDensity and findMaxDensity2. The main routine calls findMaxDensity, which is supposed to find an initial guess for the parameter mu. However (when I run the documentation example that you mention in your comment), it finds a terrible guess right on the edge, leading to an error.
When I edit the file to call findMaxDensity2 rather than findMaxDensity, it seems to produce a reasonable guess, and runs fine with no error. I can't vouch for whether the guess is actually "correct", but it seems reasonable to me, and it's only functioning as an initial guess to start off a better estimation process. (NB if you do this yourself, make sure to save a copy of the old version first).
I would guess that this is a bug, either that findMaxdensity is generating an unusually poor guess that should be caught, or that really it should be calling findMaxDensity2 and the code has not been updated to call a new subfunction.
Either way, I would report it to MathWorks.
PS I am running MATLAB R2011b. Check first if the issue has been fixed, or behaves differently, in more recent versions.
Mathworks confirmed this bug and issued a work around for it and mentioned this may be fixed in future releases.
One possible workaround is to add the following conditional at line 163 of rmabackadj function
% estimate mu from left-of-the-mode data
if any(o < mu)
mu = findMaxDensity( o(o < mu));
end
The bug for N<1000 samples has been confirmed as well but no work around has been issued yet.
I will update the thread if the work around for N<1000 samples bug.