Main Content


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

Join multiple diagnostics into a single array


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


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

Input Arguments


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

Output Arguments


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.


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, ...
                'should have been true', ...
                @() system('ps'), ...
                arbitraryValue, ...


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, ...

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