I\'m new to using MATLAB as an object-oriented environment and I\'m writing my first class to describe a network packet. A simple example would be the following
Since it is not possible to explicitly specify types for variables in Matlab, you cannot do this when declaring properties.
However, you can define a set method which checks the class and either throws an error or converts the input to whatever you want.
For example
classdef myClass
properties
myProperty = uint16(23); %# specify default value using correct type
end
methods
function obj = set.myProperty(obj,val)
if ~isa(val,'uint16')
error('only uint16 values allowed')
end
%# assign the value
obj.myProperty = val;
end
end
end