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

11 ビュー (過去 30 日間)
Matthew
Matthew 2025 年 1 月 9 日
コメント済み: Matthew 2025 年 1 月 9 日
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!

採用された回答

Matt J
Matt J 2025 年 1 月 9 日
You can do it, but you would have to define your own validation function,
  1 件のコメント
Matthew
Matthew 2025 年 1 月 9 日
Okay thanks, that's some documentation I missed. I'll give it a shot!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeArgument Definitions についてさらに検索

製品


リリース

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by