I came across some matlab code that did the following:
thing.x=linspace(...
I know that usually the . operator makes the next operation elementwise, but what does it do by itself? Is this just a sub-object operator, like in C++?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes its subobject.
You can have things like
Roger.lastname = “Poodle”;
Roger.SSID = 111234997;
Roger.children.boys = {“Jim”, “John”};
Roger.children.girls = {“Lucy”};
And the things to the right of the dots are called fields.
You can also define classes in Matlab, instatiate objects of those classes, and then if
thingwas one of those objects,thing.xwould be an instance variable in that object.The matlab documentation is excellent, look up “fields” and “classes” in it.
There are other uses for
.,M*Nmeans multiploy two things, ifM,Nare both matrices, this implements the rules for matrix multiplication to get a new matrix as its result. ButM.*Nmeans, if M, N are same shape, multiply each element. And so no like that with more subtleties, but out of scope of what you asked here.As @marc points out, dot is also used to reference fields and subfields of something matlab calls a struct or structure. These are a lot like classes, subclasses and enums, seems to me. The idea is you can have a struct
datasay, and store all the info that goes with data like this:The point is ANY matlab object/datatype/whatever you want to call it, can be referenced by a field in the struct. The last entry shows that we can even reference another struct in the field of a struct. The implication of this last bit is we could look at the date of creation of the previous verions:
To me this looks just like objects in java EXCEPT I haven’t put any methods in there. Matlab does support java objects which to me look a lot like these structs, except some of the fields can reference functions.