File Exchange

image thumbnail

Reinforcement Learning Example - Pendulum Controller w/ Animation

version (5.25 KB) by Matthew Sheen
Q-Learning how to swing and balancing a pendulum. Well-commented code with animation as it runs.


Updated 27 Jun 2016

From GitHub

View license on GitHub

Video here:
Implementation of the Q-learning algorithm. Learns a controller for swinging a pendulum upright and balancing it. Animates the entire process -- you can watch the system explore the state space and begin to get an idea of "good" and "bad" regions. Well-commented code meant to help explain the process. Lots of settings to play with and observe the results!

Cite As

Matthew Sheen (2021). Reinforcement Learning Example - Pendulum Controller w/ Animation (, GitHub. Retrieved .

Comments and Ratings (23)

Randall Kania

Rob Smith



Sai Sravan Manne

Matthew Sheen

Hi rong,
Before R2014b, you could not set or get figure properties with the dot notation. You had to use the set or get functions.
So, the line you mention would have to be axPend = get(f, 'Parent');. Probably quite a few other lines need to be converted.


It dose not work in my matlab version (R2014 a). Mistake occurs in line 124: axPend = f.Parent; How could I fix it? Any one can help?

Anh Tran

Slimane Grine

Sara Hamdan

Great Thanks

zhibin lin

Eric Anderson

Alexander Nitsch

daniel k

Zheyuan Xie

SeungHyun Lee

Siddharth Rajagopal

Jnaneshwar Das

Sai Kiran

Halit Zengin

Duy-Long HA

Shih-Jung Hsu


MATLAB Release Compatibility
Created with R2014b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!