Eagle
Eagle

Reputation: 3474

Define a static variable in matlab with the meaning like in C++

I hope that by giving an example i will be better understandable. Assuming a binary payload with 20 bytes, which contains 5 fields.

i would like to define in my class an offset variable to the beginning of each field and the size of it, so i could use it to decode the value of each variable.

I would like to avoid each time i create an instance of the class that those variable will need to be created and space allocated, rather then like C++, that then will be defined like static const... which mean it is one time defined and all other instance will use the same definition in memory.

Is this possible with Matlab?

Upvotes: 1

Views: 165

Answers (1)

Sam Roberts
Sam Roberts

Reputation: 24127

You can create a constant property in MATLAB by declaring the Constant attribute of the property:

classdef myClass
    properties (Constant = true)
        myProperty
    end
end

You will need to refer to the property qualified with the class name, for example as myClass.myProperty.

Upvotes: 2

Related Questions