Main Content

join

Class: matlab.automation.diagnostics.Diagnostic
Package: matlab.automation.diagnostics

Join multiple diagnostics into a single array

Syntax

diagArray = join(diag1,...,diagN)

Description

diagArray = join(diag1,...,diagN) joins multiple diagnostics, specified by diag1 through diagN, into a single array, diagArray.

Input Arguments

diag

Diagnostic content, specified as a Diagnostic object, string array, character array, function handle, or arbitrary type.

Output Arguments

diagArray

Array of joined diagnostic content:

  • If diag is an object that derives from Diagnostic, it is included in the array unmodified.

  • If diag is a string or character array, it is converted to a StringDiagnostic object and included in the array.

  • If diag is a function handle, it is converted to a FunctionHandleDiagnostic object and included in the array.

  • If diag is any other type, it is converted to a DisplayDiagnostic object and included in the array.

Examples

expand all

        % The following example creates a diagnostic array of length 4,
        % demonstrating standard Diagnostic conversions. Note:
        % MyCustomDiagnostic is for example purposes and is not executable
        % code.
 
        import matlab.automation.diagnostics.Diagnostic
        import matlab.unittest.constraints.IsTrue
 
        arbitraryValue = 5;
        testCase.verifyThat(false, IsTrue, ...
            Diagnostic.join(...
                'should have been true', ...
                @() system('ps'), ...
                arbitraryValue, ...
                MyCustomDiagnostic))

Alternatives

You can use array concatenation to join diagnostics into an array if at least one of the values is a Diagnostic object. The join method prevents the need to have any Diagnostic objects in the array. Considering the following example.

arbitraryValue = 5;
testCase.verifyThat(false, IsTrue, ...
    ['should have been true', ...
    @() system('ps'), ...
    arbitraryValue, ...
    MyCustomDiagnostic]);

Since MyCustomDiagnostic is a Diagnostic object, the other values are correctly converted to diagnostics as well.