nelson.mixin.indexing.RedefinesBrace
Customize brace indexing of a class.
📝Syntax
classdef MyClass < nelson.mixin.indexing.RedefinesBrace
📥Input Arguments
Parameter Description
obj an object of a class deriving from nelson.mixin.indexing.RedefinesBrace.
📤Output Arguments
Parameter Description
obj an object supporting customized brace indexing.
📄Description

Derive from nelson.mixin.indexing.RedefinesBrace to give a class its own brace indexing behavior. A subclass implements the protected methods braceReference(obj, indexOp) (value of obj{...}), braceAssign(obj, indexOp, value) (obj{...} = value) and braceListLength(obj, indexOp, indexContext).

indexOp is a nelson.indexing.IndexingOperation whose Indices property is a cell array of the subscripts.

💡Examples
A cell-like container.
classdef Bag < nelson.mixin.indexing.RedefinesBrace
  properties
    Data
  end
  methods
    function obj = Bag(x)
      obj.Data = x;
    end
  end
  methods (Access = protected)
    function varargout = braceReference(obj, indexOp)
      varargout{1} = obj.Data{indexOp.Indices{1}};
    end
    function obj = braceAssign(obj, indexOp, val)
      obj.Data{indexOp.Indices{1}} = val;
    end
    function n = braceListLength(obj, indexOp, ctx)
      n = 1;
    end
  end
end
🔗See Also
nelson.mixin.indexing.RedefinesParennelson.indexing.IndexingOperation
🕔Version History
Version Description
2.0.0 initial version
Edit this page on GitHub