Class Property Validation for the Contents of a Cell Array Property?

5 views (last 30 days)
I'm writing a class that stores its data in the form of cell arrays, matching values to their units. An example property definition might look something like:
classdef myClass
properties (SetAccess = private)
prop1 (2, 2) cell = { 1000, "m" ; 1, "km" }
end
end
In the class definition, I'd like to use property validation to restrict the values in column 1 to valid distances, nonnegative for example, and column 2 to valid strings that define an actual unit type, "m"/"ft"/"in" for example. This is trivial for defined types, like 'int16' or 'double', but I'm wondering if anyone has accomplished this for columns/rows inside a cell array. The goal here is to store property value with its unit, while also restricting both to valid input. Is this possible given the cell type at property definition? Thanks!

Accepted Answer

Matt J
Matt J on 9 Jan 2025
You can do it, but you would have to define your own validation function,

More Answers (0)

Categories

Find more on Argument Definitions in Help Center and File Exchange

Products


Release

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!