matlab.lang.invalidHandle - Construct array of invalid handles - MATLAB (original) (raw)
Construct array of invalid handles
Since R2024b
Syntax
Description
`invArr` = matlab.lang.invalidHandle([classname](#mw%5F2f2f0b74-0bd5-4814-9dc3-2420d7b3c192))
returns an invalid handle to a scalar instance of classname
. No object of classname
is constructed.
`invArr` = matlab.lang.invalidHandle([classname](#mw%5F2f2f0b74-0bd5-4814-9dc3-2420d7b3c192),[sz1,...,szN](#mw%5F302943d1-a669-47b5-9bee-276e15df7c42))
returns an array of invalid handles with dimensions specified bysz1,...,szN
.
Examples
Create a 2-by-3 array of invalid handles to TrialData
objects. (See the end of the example for the TrialData
class code.)
h = matlab.lang.invalidHandle("TrialData",2,3)
h =
2×3 TrialData array with properties:
trialNumber
trialResults
Access one of the array elements to verify that it holds a handle to a deletedTrialData
object.
ans =
handle to deleted TrialData
Code for TrialData
Class
classdef TrialData < handle properties trialNumber string = "A001" trialResults double = 0 end end
Properties defined using the WeakHandle
attribute must use class validation. When WeakHandle
properties define a default value, that default must be an empty array or an invalid handle array that satisfies the class validation.
Create a class that defines a WeakHandle
property of classTrialData
with size (1,3). (See the end of Create Array of Invalid Handles for theTrialData
class code.) Usematlab.lang.invalidHandle
to create a default value for the property.
classdef WeakDefault properties (WeakHandle) Prop1 (1,3) TrialData = matlab.lang.invalidHandle("TrialData",1,3) end end
Construct an instance of the class.
wd =
WeakDefault with properties:
Prop1: [1×3 TrialData]
Access one of the elements of wd.Prop1
to verify that it holds a handle to a deleted instance of TrialData
.
ans =
handle to deleted TrialData
Input Arguments
Class for which to create an invalid handle, specified as a string scalar or character vector. Valid inputs include names of fundamental MATLAB® classes (see Fundamental MATLAB Classes) as well as user-defined classes.
Size of each dimension, specified as two or more integer values. The output is asz1
-by-...-by-szN
array.
- If the size of any dimension is
0
, then the output is an empty array. - If the size of any dimension is negative, then it is treated as
0
. - If trailing dimensions greater than
2
have a size of1
, then the output does not include those dimensions. For example,matlab.lang.invalidHandle(_`classname`_,3,1,1,1)
returns a 3-by-1 vector of invalid handles to objects of_classname
_.
Tips
matlab.lang.invalidHandle
errors for classes that overridecopy
in such a way that the method errors for invalid handles.
Version History
Introduced in R2024b