Main Content


Pauli Z gate

Since R2023a

Installation Required: This functionality requires MATLAB Support Package for Quantum Computing.



g = zGate(targetQubit) applies a Pauli Z gate to a single target qubit and returns a quantum.gate.SimpleGate object.

If targetQubit is a vector of qubit indices, zGate returns a column vector of gates, where g(i) represents a Pauli Z gate applied to a qubit with index targetQubit(i).


collapse all

Create a Pauli Z gate that acts on a single qubit.

g = zGate(1)
g = 

  SimpleGate with properties:

             Type: "z"
    ControlQubits: [1×0 double]
     TargetQubits: 1
           Angles: [1×0 double]

Get the matrix representation of the gate.

M = getMatrix(g)
M =

     1     0
     0    -1

Create an array of Pauli Z gates that act on qubits with indices 1 to 4.

g = zGate(1:4)
g = 

  4×1 SimpleGate array with gates:

    Id   Gate   Control   Target
     1   z                1     
     2   z                2     
     3   z                3     
     4   z                4     

Input Arguments

collapse all

Target qubit of the gate, specified as a positive integer scalar index or vector of qubit indices.

Example: 1

Example: 3:5

More About

collapse all

Matrix Representation of Pauli Z Gate

The matrix representation of a Pauli Z gate applied to a single qubit is


This gate leaves the |0 state as is and maps the |1 state to |1. This gate is also known as a phase-flip gate.

Version History

Introduced in R2023a