Main Content


Class: matlab.unittest.diagnostics.Diagnostic
Package: matlab.unittest.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 an instance of a Diagnostic object, a string array, a character array, a function handle, or an arbitrary type.

Output Arguments


Array of joined diagnostic content.

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

  • If diagN is a char or a string, it is formed into a StringDiagnostic and included in the array.

  • If diagN is a function_handle, it is formed into a FunctionHandleDiagnostic and included in the array.

  • If diagN is any other type, it is formed into a DisplayDiagnostic 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.unittest.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 join diagnostics into an array if at least one of the values is a diagnostic. The join method prevents the need to have any Diagnostics 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, the other values are correctly converted to diagnostics as well.