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.

example

Examples

collapse all

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

collapse all

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.

Tips

Version History

Introduced in R2024b