Effacer les filtres
Effacer les filtres

Question about Use property validation

2 vues (au cours des 30 derniers jours)
Derek Jing
Derek Jing le 11 Fév 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 commentaire
Derek Jing
Derek Jing le 11 Fév 2022
or following
prefNames(:,1) string = string.empty;
numPrefs(1,1) uint8 = 0;

Connectez-vous pour commenter.

Réponses (1)

Steven Lord
Steven Lord le 11 Fév 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.)

Catégories

En savoir plus sur Argument Definitions dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by