MATLAB, Phased Array Toolbox and `pattern` function - matlab

I'm trying to understand an example for MATLAB Phased Array Toolbox.
There is called function pattern:
pattern(ha,fc,-180:180,0,'Type','powerdb',...
'CoordinateSystem','rectangular','PropagationSpeed',c)
Cannot you tell me, where is the function described and what does it do?

pattern is a method on antenna array objects. ha is an instance of the class phased.ReplicatedSubarray. When object is the first argument to a call, MATLAB first checks whether this is a method on that object and calls that. This syntax is same as calling ha.pattern(...). If you try methods(ha) it should list pattern as one of the methods. You can find documentation for pattern method of this object at http://www.mathworks.com/help/phased/ref/phased.replicatedsubarray.pattern.html.

Related

Methods of Matlab's Built-in Objects

What are the differences between these two calling sequences get(a) and a.get()?
load gong
a = audioplayer(y, Fs);
a.get
get(a)
There is no difference by default. However, the behavior can be modified.
By default, for an object of a custom class, obj.method(arg1,arg2,...) is syntactic sugar for method(obj,arg1,arg2,...). This means that when you write the former, MATLAB pretends you wrote the latter and proceeds accordingly.
However, it is possible to overload the method subsref for the class, in which case this function will be called for the syntax obj.method(arg1,arg2,...). That is, MATLAB interprets it as an indexing operation (.method) followed by another indexing operation ((arg1,arg2,...)). The subsref method is called to evaluate these indexing operations. It is possible to implement it such that the appropriate method is called in this case, but custom indexing code is executed for other indexing operations such as obj(x) or obj{x}. See for example here.

Equivalent of R's str in Matlab? [duplicate]

I'd like to be able to view the structure of objects in Matlab/GNU Octave the same way as I do in R (using the str() function). Is there a function that does this? An example task would be returning nr rows and cols in matrix, but also all the arguments for a given function.
I'm aware that I could use both size() and help() (but not for function files) separately to get this information.
There are several useful functions for displaying some information about Matlab objects (I can't say anything about Octave compatibility), but I'm not sure they'll provide the same detail as R's str(). You can display all of the methods of a class with the methods function, e.g.:
methods('MException')
which returns
Methods for class MException:
addCause getReport ne throw
eq isequal rethrow throwAsCaller
Static methods:
last
The what function will return similar results. Or methods can be used on an object of a given class:
ME = MException('Test:test','Testing');
methods(ME)
Similarly, you can view the properties with properties and the events with events.

New MATLAB version overrides my function with class method. Can I still call my function?

I had a function in a file harmonic.m in my matlab path with prototype:
function D = harmonic(A,B,C)
where, importantly, A is expected to be a matrix of type double.
In version r2014a, apparently MATLAB has created a new builtin class method double.harmonic. Thus when I call my function I get an error inside the wrong harmonic. It doesn't help that my harmonic is closer in the path list (which harmonic reveals my path) because my first input is A and harmonic(A,B,C) seems to be equivalent to A.harmonic(B,C).
Is there any way to call my function directly? To ignore this double.harmonic function? I know I can create a function handle from the path, but that's nasty. I'm looking for a more elegant solution or workaround. The most obvious being change my function's name, but then I'll feel bullied : - (.
Put your version of harmonic into a folder #double, and make sure that your folder #double is above \toolbox\symbolic\symbolic\#double on the path (this new double.harmonic is from Symbolic Toolbox).
That will force your function to become a method of double i.e. it will be double.harmonic, rather than a generic function harmonic. When deciding which thing to dispatch to, MATLAB will consider methods first, then generic functions later. Since your double.harmonic and the other one are both methods, and yours is ahead on the path, yours will win. BAM - eat that, MATLAB!

about matlab's Adaptfilt.<algorithm> function

Matlab's DSP toolbox has a function called adaptfilt., where calling adaptfilt is not enough, but you must add the .< algorithm> where the algorithm can be one of the many things, which we can view using help adaptfilt. What kind of Matlab structure has been used here (or what is the . operator and how can I make my own function that has to be called using a dot).
Also, the result of doing, say, adaptfilt.fdaf, gives a result that seems like a structure. How can I view all the elements of this structure (that is, if there are any more members besides the values that are returned on the screen by the function itself)?
adaptfilt is a class definition, of which fdaf is a member. Then, you use the dot operator to access the static member of the class. See Static Methods in the MATLAB documentation. In summary, to define a similar function yourself use
classdef MyClass
...
methods(Static)
function y = yourFunc(x)
...
end
end
end
The result you're getting from adaptfilt.fdaf is in fact an object. The adaptfilt.fdaf documentation page outlines the members of the object.

The use of "this" in every MATLAB class

Why is that in every class in MATLAB I must use "this"? I think that in C++ I don't need to use "this", only if I want to. Is this also the case in MATLAB?
In short, you must use some kind of explicit reference.
First of all, unlike in C++/C#/Java where it is named this, you can use any name you want.
The reason that you must use explicit calls is Matlab designers decision.
The idea was to support Matlab vector operations on objects, as if they are
structs. The following is a fragment from the link above:
While languages with an implicit object parameter provide a "this" keyword
to access the implicit object, they usually do not require you to access a
property through "this". If MATLAB had implicit properties, the logical
extension to array-based objects would be to index into nothing:
S = S + (k).Value;
Edit:
Following the good comment of #AndrewJanke, I would like to add that MATLAB could have had this as implicit reference, and only force to use it in indexing of array-based objects. Nevertheless, this approach was not chosen by MATLAB designers.