필터 지우기
필터 지우기

Question about Use property validation

조회 수: 2 (최근 30일)
Derek Jing
Derek Jing 2022년 2월 11일
답변: Steven Lord 2022년 2월 11일
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