# qiskit - measure only 1 of the register out of n registers

I have created a 9 qubit register:

q = QuantumRegister(9)
c = ClassicalRegister(9)
qc = QuantumCircuit(q, c)


I want to measure only 1 of the register(let's suppose i want to measure the 5th register.) How do I implement the code?

qc.measure(q[register],c[register])
job = execute(qc,simulator,shots = 1000)
result = job.result()
counts = result.get_counts(qc)
print("\nTotal count for 0 and 1 are:",counts)


My code seems to measure all 9 registers.

• Hi @Hon Lin! Could you elaborate on "my code seems to measure all 9 registers"? What makes you tell us that? The results of the code snippet? If so, could you provide them? Aug 22 '19 at 7:07
• Hi @Nelimee, the counts give '000000000' and '000000001' as the output, thus not realizing the default setting from the classical register, I jumped into a very wrong conclusion that all 9 quantum registers have been measured. Aug 30 '19 at 7:16

In qiskit, if there are classical bits that are not getting a value through a measurement gate, they will default to '0'. Since you set your circuit up to have 9 classical bits, the counts will always be bit strings of length 9, even though you are only measuring 1 qubit.

To only measure one qubit, and have that be the only value in the resulting bit string, you need to only have one classical bit in your circuit.

q = QuantumRegister(9)
c = ClassicalRegister(1) # Changed from 9 to 1
qc = QuantumCircuit(q, c)
qc.measure(q[register],c)
job = execute(qc,simulator,shots = 1000)
result = job.result()
counts = result.get_counts(qc)
print("\nTotal count for 0 and 1 are:",counts)