主要内容

CustomTolerance

R2026b

Custom tolerance

Since R2026b

    Description

    Add-On Required: This feature requires the Optical Design and Simulation Library for Image Processing Toolbox add-on.

    A CustomTolerance object defines a custom tolerance that uses a custom function to perturb an optical system during sensitivity or Monte Carlo tolerance analysis.

    Creation

    Description

    tol = optics.tolerance.CustomTolerance(fcnHandle,value) creates a custom tolerance that uses the function specified by fcnHandle to perturb the optical system with a tolerance range defined by value.

    tol = optics.tolerance.CustomTolerance(fcnHandle,value,arg1,...,argN) passes the additional arguments arg1,...,argN to the custom tolerance function.

    example

    tol = optics.tolerance.CustomTolerance(___,Name=name) specifies a descriptive name for the custom tolerance.

    Input Arguments

    expand all

    Custom tolerance function, specified as a function handle. The function must accept at least two input arguments: an opticalSystem object and a scalar perturbation value. It must return exactly two output arguments: the modified opticalSystem object and the nominal scalar value.

    Data Types: function_handle

    Tolerance range, specified as a 1-by-2 numeric vector of the form [min max] representing the absolute perturbation range. Unlike built-in tolerances, custom tolerances do not support percentage values.

    Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

    Additional input arguments for the custom tolerance function, specified as a comma-separated list. The types of the inputs depend on the function fcnHandle. These arguments are inputs to fcnHandle after the optical system and perturbation value arguments.

    Tolerance name, specified as a string scalar or character vector. Use this argument to identify the custom tolerance in the tolerance set table.

    Data Types: char | string

    Properties

    expand all

    This property is read-only.

    Property to which the tolerance applies, represented as a string scalar.

    Data Types: string

    This property is read-only.

    Custom perturbation function, represented as a function handle.

    This property is read-only.

    Custom function arguments, represented as a cell array containing the additional arguments passed during object creation.

    Target index, specified as an empty array. Custom tolerances do not use target index resolution.

    Tolerance range, specified as a 1-by-2 numeric vector [min max].

    Data Types: double

    This property is read-only.

    Tolerance interpretation type, represented as "Absolute". Custom tolerances always use absolute ranges.

    Object Functions

    applyApply tolerance perturbation to optical system

    Examples

    collapse all

    Import an optical system into the workspace.

    opsys = zmximport("PhotographicLens.zmx");

    Define a custom tolerance. The custom tolerance function modifyGap is defined at the end of this example.

    tol = optics.tolerance.CustomTolerance(@modifyGap,[-0.1 0.1])
    tol = 
      CustomTolerance with properties:
    
           TargetProperty: "Custom"
        ToleranceFunction: @modifyGap
            CustomFcnArgs: {1×0 cell}
              TargetIndex: [1×0 double]
           ToleranceRange: [-0.1000 0.1000]
            ToleranceType: "Absolute"
    
    

    Apply the tolerance to the optical system.

    newopsys = apply(tol,opsys);

    Custom Function

    The modifyGap function computes how much to adjust the gap after a specific component and updates the component position. The function gets the current gap after a given component, increases or decreases it according to the perturbation value, and then updates the position of the component to reflect the new gap value.

    function [opsys,requiredGap] = modifyGap(opsys,gapValue)
        compIndex = 2;
        if length(opsys.Components) <= compIndex
            error("Invalid component index")
        end
        currentGap = distanceAfter(opsys,compIndex);
        requiredGap = currentGap-gapValue;
        opsys.Components(compIndex).Position(3) = opsys.Components(compIndex).Position(3)+requiredGap;
    end

    Version History

    Introduced in R2026b