Question about Use property validation

1 visualización (últimos 30 días)
Derek Jing
Derek Jing el 11 de Feb. de 2022
Respondida: Steven Lord el 11 de Feb. de 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 comentario
Derek Jing
Derek Jing el 11 de Feb. de 2022
or following
prefNames(:,1) string = string.empty;
numPrefs(1,1) uint8 = 0;

Iniciar sesión para comentar.

Respuestas (1)

Steven Lord
Steven Lord el 11 de Feb. de 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.)

Categorías

Más información sobre Argument Definitions en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by