File Exchange

image thumbnail

Artificial horizon

version (10.8 KB) by Eric Ogier
On screen artificial horizon for aircraft


Updated 16 Mar 2019

View License

"Artificial horizon" is a graphical object consisting of an on screen artificial horizon for aircraft, including:
- Virtual horizon line between sky and ground symbols
- Reticle symbolising aircraft longitudinal axis
- Flight path marker
- Attitude indicators :
. Pitch indicator, range : ]-180°,+180°], field of view : 40°
. Roll indicator, range : ]-180°,+180°], field of view : 60°
. Heading indicator, range : [-90°,+90°], field of view : 60°
All attitude gauges have the following characteristics:
- Reference markings : cardinal points, null pitch and null roll
- Resolution of 2.5° for graduating
- Specific graduatings for modulo 2.5°, 5° and 10° angles
Attitude can be updated by an object method through the three Euler angles [rad], respecting this aeronautical convention: from an initial attitude (North, horizontal flight), heading, pitch and roll angles respectively increase when:
- Aircraft turns to the East
- Aircraft climbs
- Right wing goes down

Video demonstrations:

Cite As

Eric Ogier (2019). Artificial horizon (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (16)

Eric Ogier

It should be possible to use a block "Embedded MATLAB Function" that creates an artificial horizon and then to provide HEADING, PITCH and ROLL to it or to update HEADING, PITCH and ROLL with angle increments from an initial attitude:


persistent AH

if isempty(AH)
AH = Artificial_horizon(PROPERTY1,VALUE1,PROPERTY2,VALUE2,...);


Ken Yano

Hello Eric, is there any way I can link your GUI into a Simulink system and feed it with MPU9250 data?

Eric Ogier

Hello Kelly,

You can add an artificial horizon programmatically in your own figure by specifying its axes.
At the end of the instructions creating the figure of your application, you can create axes belonging to the figure and call Artificial_horizon object specifying the axes you created as the value of "axes" property:
Axes = axes('parent',YourFigure);
AH = Artificial_horizon('axes',Axes);
Then, you can update it with your attitude data through "update" method. If you want to update the location of the horizon, e.g when the main figure is resized, you have to update "position" property.

I hope it will help.

Hi Eric ,
Do you think it is possible to add your artificial horizon "inside" an app made in app designer ?
For the moment I can only have it in a separate "figure" window so it is not really integrated in my app..

Forgot the stars ;)

Very nice! Thanks for sharing.

Mo Wo

Really gerat work! Thanks a lot!

Great work!

There is a small bug in heading indicator update (line 571):

Object.HeadingIndicator.Lines(n) should be updated by using the set function (not line), otherwise wrong axes are used.

Two thumbs up!

Eric Ogier

Could you confirm the artificial horizon doesn't remain static with the following test (make sure the unit you use is radian) ?

% Figure
S = get(0,'ScreenSize');
d = 500;
P = [(S(3)-d)/2 (S(4)-d)/2 d d];
figure('Color', 'w',...
'MenuBar', 'none',...
'Position', P);

% Creation of an artificial horizon
AH = Artificial_horizon('Axes',gca,'ReticleType','-.-','Reticlecolor','y','EdgeColor','w');

% Test

the problem is that not appear the value's scale in the graph (for example +10º, +20º, +30º). Only appears 0º.


Eric Ogier


It is an arbitrary choice not to display too much information.

If you need the precise values of roll, pitch and heading, typically in yellow in black boxes, you can add the following lines at the end of the given functions:

• % Artificial horizon update
function update(Object,Heading,Pitch,Roll)


set(Object.PitchIndicator.StaticBox, 'String',sprintf('%+.0f°',180/pi*Pitch));
set(Object.RollIndicator.StaticBox, 'String', sprintf('%+.0f°',180/pi*Roll));
set(Object.HeadingIndicator.StaticBox, 'String', sprintf('%+.0f°',180/pi*Heading));

• % Creation of a pitch indicator
function Creation_pitch_indicator(Axes)


Object.PitchIndicator.StaticBox = ...
'Parent', Axes,...
'Color', 'y',...
'EdgeColor', 'y',...
'Backgroundcolor', 'k',...
'FontSize', Object.FontSize,...
'FontWeight', Object.FontWeight,...
'HorizontalAlignment', 'Center',...
'VerticalAlignment', 'Middle');

• % Creation of a roll indicator
function Creation_roll_indicator(Axes)


Object.RollIndicator.StaticBox = ...
'Parent', Axes,...
'Color', 'y',...
'EdgeColor', 'y',...
'Backgroundcolor', 'k',...
'FontSize', Object.FontSize,...
'FontWeight', Object.FontWeight,...
'HorizontalAlignment', 'Center',...
'VerticalAlignment', 'Middle');

• % Creation of a heading indicator
function Creation_heading_indicator(Axes)


Object.HeadingIndicator.StaticBox = ...
'Parent', Axes,...
'Color', 'y',...
'EdgeColor', 'y',...
'Backgroundcolor', 'k',...
'FontSize', Object.FontSize,...
'FontWeight', Object.FontWeight,...
'HorizontalAlignment', 'Center',...
'VerticalAlignment', 'Bottom');

This solution works well for me.

Hi Eric

the values of heading, pitch and roll not appear in the graph. Why?

good job

Eric Ogier

Hello Alexander,

I managed to link this artificial horizon to a test GUI including axes and a push button.
I created axes titled ‘axes1’ and defined the following ‘Create function’:
% --- Executes during object creation, after setting all properties.
function axes1_CreateFcn(hObject, eventdata, handles)
% hObject handle to axes1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: place code in OpeningFcn to populate axes1
AH = Artificial_horizon('Axes',hObject,'Position',[0 0 0.5 0.5]);

This callback function is called at the creation of the axes, whose handles, ‘hObject’, will be injected in Artificial_horizon object as ‘Axes’ property. There is a little subtlety in the fact you must use 'normalized' unit (the default unit in GUIDE is ‘character’). In this example, an artificial horizon should appear in the bottom left quadrant of the GUI.

I hope it will help you.


Hi Eric,

I am trying to add this artificial horizon in a GUI that I've created.

The issue is that I am not able to add it inside an axes object, that is already embedded in the GUI.

Do you have any hints?

Thank you,



Minor modification to avoid errors if the parent figure is closed by user.

Update with flight path marker and new reticles

Minor modification for taking into account the dimensions of an existing axis in 'create' function.

Modification of video demonstrations links.

Modification of heading gauge to indicate horizon line direction.

Adding of video demonstrations link.

MATLAB Release Compatibility
Created with R2018a
Compatible with R2016b to any release
Platform Compatibility
Windows macOS Linux

Discover Live Editor

Create scripts with code, output, and formatted text in a single executable document.

Learn About Live Editor