Main Content

spy

Visualize sparsity pattern of a sparse model

    Description

    example

    spy(sys) plots the sparsity pattern of the sparse model sys, which can be a first-order (sparss) or second-order (mechss) model. The plot displays the number of nonzero elements in each sparse matrix of sys. To display a matrix, right click the plot and select the desired matrix.

    spy(AX,sys) plots the sparsity pattern on the Axes or UIAxes object in the current figure with the handle AX. Use this syntax when creating apps with spy in the App Designer.

    Examples

    collapse all

    For this example, consider sparseFOContinuous.mat which contains sparse matrices for a continuous-time sparse first-order state-space model.

    Extract the sparse matrices from sparseFOContinuous.mat.

    load('sparseFOContinuous.mat','A','B','C','D','E');

    Create the sparss model object.

    sys = sparss(A,B,C,D,E)
    Sparse continuous-time state-space model with 1 outputs, 1 inputs, and 199 states.
    
    Use "spy" and "showStateInfo" to inspect model structure. 
    Type "properties('sparss')" for a list of model properties. 
    Type "help sparssOptions" for available solver options for this model.
    

    The output sys is a continuous-time sparss model object containing with 199 states, 1 input and 1 output.

    You can use the spy command to visualize the sparsity of the sparss model object.

    spy(sys)

    Figure contains an axes object. The axes object with title nnz: A=239, E=239, B=20, C=19, D=1. contains 7 objects of type line. These objects represent A, B, C, D.

    For this example, consider sparseFODiscrete.mat which contains sparse matrices for a discrete-time sparse first-order state-space model.

    Extract the sparse matrices from sparseFODiscrete.mat.

    load('sparseFODiscrete.mat','A','B','C','D','E','ts');

    Create the sparss model object.

    sys = sparss(A,B,C,D,E,ts)
    Sparse discrete-time state-space model with 1 outputs, 1 inputs, and 398 states.
    
    Use "spy" and "showStateInfo" to inspect model structure. 
    Type "properties('sparss')" for a list of model properties. 
    Type "help sparssOptions" for available solver options for this model.
    

    The output sys is a discrete-time sparss model object containing with 398 states, 1 input and 1 output.

    You can use the spy command to visualize the sparsity of the sparss model object.

    spy(sys)

    Figure contains an axes object. The axes object with title nnz: A=518, E=837, B=56, C=18, D=1. contains 7 objects of type line. These objects represent A, B, C, D.

    You can also view model properties of the sparss model object.

    properties('sparss')
    Properties for class sparss:
    
        A
        B
        C
        D
        E
        Scaled
        StateInfo
        SolverOptions
        InternalDelay
        InputDelay
        OutputDelay
        Ts
        TimeUnit
        InputName
        InputUnit
        InputGroup
        OutputName
        OutputUnit
        OutputGroup
        Notes
        UserData
        Name
        SamplingGrid
    

    For this example, consider the sparse matrices for the 3-D beam model subjected to an impulsive point load at its tip in the file sparseBeam.mat.

    Extract the sparse matrices from sparseBeam.mat.

    load('sparseBeam.mat','M','K','B','F','G','D');

    Create the mechss model object by specifying [] for matrix C, since there is no damping.

    sys = mechss(M,[],K,B,F,G,D)
    Sparse continuous-time second-order model with 3 outputs, 1 inputs, and 3408 degrees of freedom.
    
    Use "spy" and "showStateInfo" to inspect model structure. 
    Type "properties('mechss')" for a list of model properties. 
    Type "help mechssOptions" for available solver options for this model.
    

    The output sys is a mechss model object containing a 3-by-1 array of sparse models with 3408 degrees of freedom, 1 input, and 3 outputs.

    You can use the spy command to visualize the sparsity of the mechss model object.

    spy(sys)

    Figure contains an axes object. The axes object with title nnz: M=71076, K=212802, B=1, F=3, G=973. contains 9 objects of type line. These objects represent K, B, F, D.

    For this example, consider the sparse matrices of the discrete system in the file discreteSOSparse.mat.

    Load the sparse matrices from discreteSOSparse.mat.

    load('discreteSOSparse.mat','M','C','K','B','F','G','D','ts');

    Create the discrete-time mechss model object by specifying the sample time ts.

    sys = mechss(M,C,K,B,F,G,D,ts)
    Sparse discrete-time second-order model with 1 outputs, 1 inputs, and 28408 degrees of freedom.
    
    Use "spy" and "showStateInfo" to inspect model structure. 
    Type "properties('mechss')" for a list of model properties. 
    Type "help mechssOptions" for available solver options for this model.
    

    The output sys is a discrete-time mechss model object with 28408 degrees of freedom, 1 input, and 1 output.

    You can use the spy command to visualize the sparsity pattern of the mechss model object. You can right-click on the plot to select matrices to be displayed.

    spy(sys)

    Figure contains an axes object. The axes object with title nnz: C=524538, K=1750850, B=28408, F=71, D=1. contains 9 objects of type line. These objects represent K, B, F, D.

    Input Arguments

    collapse all

    Sparse model, specified as a one of the following objects.

    • sparss — First-order sparse model

    • mechss — Second-order sparse model

    When sys contains interfaced or interconnected components, use spy(xsort(sys)) to view the underlying block arrow structure. For more information about the block arrow structure, see xsort.

    Object handle, specified as an Axes or UIAxes object. Use AX to create apps with spy in the App Designer.

    Introduced in R2020b