How do I use a class property validation function with a dynamic argument?

9 ビュー (過去 30 日間)
Jan Siegmund
Jan Siegmund 2020 年 11 月 14 日
回答済み: Jan Siegmund 2020 年 11 月 14 日
In Matlab OOP, I wanna use a function like mustBeEqualSize(a,b) from the Examples on function property validation to validate a property:
classdef foo
properties
a
b {mustBeEqualSize(a,b)}
end
end
However, this gives me an error.

採用された回答

Jan Siegmund
Jan Siegmund 2020 年 11 月 14 日
The problem is, that MATLAB classes only support constant arguments on property validation.
However function arguments can be validated perfectly fine with dynamic arguments.
So a workaround is to validate the arguments of the constructor:
classdef Foo
properties
a
b
end
methods
function obj = Foo(a,b)
arguments
a
b {mustBeEqualSize(a,b)}
end
obj.a = a;
obj.b = b;
end
end
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSoftware Development Tools についてさらに検索

タグ

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by