Question about Use property validation

2 次查看(过去 30 天)
The property definition of my class is as following:
classdef ClassName
properties
prefNames@string vector = string.empty;
numPrefs@uint8 scalar = 0;
end
.......
I got warning as following:
Warning: Class 'ClassName' uses an undocumented syntax to restrict property values. Use property
validation syntax instead. This warning will become an error in a future release.
I checked Matlab help and see I shall ue following sytax
Prop(dim1,dim2,...) classname (func1, func2,...) = default value
So I convert above property definition as following:
prefNames string = string.empty;
numPrefs uint8 = 0;
My question is: how to define the size of the string vector in the property validation when the size of the vector is unknown in advance
  1 个评论
Derek Jing
Derek Jing 2022-2-11
or following
prefNames(:,1) string = string.empty;
numPrefs(1,1) uint8 = 0;

请先登录,再进行评论。

回答(1 个)

Steven Lord
Steven Lord 2022-2-11
You can use a colon in the size validation section of the property definition (see Property Size Validation on this documentation page) or if you don't want to restrict the prefNames to be a row vector or a column vector (just make it be a vector or an empty) use the mustBeVector property validation function (with the "allow-all-empties" option since your default value is an empty not a vector.)

类别

Help CenterFile Exchange 中查找有关 Agriculture 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by