Clear Filters
Clear Filters

Question about Use property validation

2 views (last 30 days)
Derek Jing
Derek Jing on 11 Feb 2022
Answered: Steven Lord on 11 Feb 2022
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 Comment
Derek Jing
Derek Jing on 11 Feb 2022
or following
prefNames(:,1) string = string.empty;
numPrefs(1,1) uint8 = 0;

Sign in to comment.

Answers (1)

Steven Lord
Steven Lord on 11 Feb 2022
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.)

Categories

Find more on Agriculture in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!