View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
READHGT: Import/download NASA SRTM data files (.HGT)

Join the 15-year community celebration.

Play games and win prizes!

» Learn more

4.9 | 14 ratings Rate this file 37 Downloads (last 30 days) File Size: 64.6 KB File ID: #36379 Version: 2.4
image thumbnail

READHGT: Import/download NASA SRTM data files (.HGT)



25 Apr 2012 (Updated )

Imports or download SRTM worldwide digital elevation model data files.

| Watch this File

File Information

This function imports .HGT "height" binary data files from NASA SRTM global digital elevation model of Earth land, corresponding to 1x1 degree tiles of 3-arc seconds resolution (SRTM3, around 90 m) and 1-arc second (SRTM1, around 30 m), and returns coordinates vectors latitude and longitude, and a matrix of elevation values.
The function includes also an automatic download of data from the USGS SRTM webserver, so indicating latitude and longitude is sufficient to get the data and instant map plot anywhere in the World.
Few examples:
plots a map of Seattle and surrounding volcanoes,
   X = readhgt(48,2,'plot');
plots a map of Paris (France) and returns downloaded SRTM data in structure X.
Type "doc readhgt" for syntax, options, other examples and use.

Required Products MATLAB
MATLAB release MATLAB 7.13 (R2011b)
MATLAB Search Path
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (26)
13 Sep 2016 Zach

Zach (view profile)

A great resource. Thank you!!!

07 Jul 2016 François Beauducel

Dear Jeremiah,

Thanks for your feedback.

Actually the height values of SRTM data are elevation above the geoid and not ellipsoid. The geoid is equivalent to the long-term mean sea level.

Converts these data to ellipsoid reference like WGS84 is quite easy to do... good suggestion ! for a future release ?

Comment only
02 Jun 2016 Jeremiah Graber


Thank you for the awesome file.

I was hoping for clarification on what height is reported. In reading about SRTM it appears height is listed either as height above the WGS84 ellipsoid or the EGM96 ellipsoid. Your code says it returns height above sea level.

Could you confirm which height you are returning? Also, would it be possible to have an option to return height above WGS84 ellipsoid? The offset is given in the data.

28 May 2016 E. Ch3yn3t  
24 Nov 2015 François Beauducel

Dear akfarell,
If you need the full indexing, you must use the meshgrid function:
then lon,lat and X.z have the same size and indexed the same way.

Comment only
23 Nov 2015 akfarrell

Dear Francois,
Just to clarify, how is the z matrix indexed with reference to the latitude and longitude values? Is it (lat(1:end), lon(1:end))? Thank you!

Comment only
19 Nov 2015 akfarrell  
22 Aug 2015 Paolo

Paolo (view profile)

26 Apr 2015 mohamed nazih

thank you

Comment only
17 Oct 2014 vinod pillai

Dear Francois,
Thanks for the suggestion,

vinod pillai

Comment only
15 Oct 2014 François Beauducel

Dear Vinod,
SRTM .hgt files are freely available at
Once downloaded, a single tile (1 by 1 degree) is coded as a simple matrix of 1201 by 1201 binary int16 values, big-endian. No header. Integer values represent elevations in meter. -32768 value means "no data".
For SRTM1 tiles (USA territories), tiles are 3601 by 3601.
That's all. See online documentation for further details but this is easily readable in any language.

Comment only
15 Oct 2014 vinod pillai

Dear Francois,

I joined Matworks today only, while searching for some help on extracting height from SRTM file, and happen to catch your link. Though i have not worked on MATLAB, is there any other way ( say in VB.NET) to capture the height from SRTM .hgt.



Comment only
02 Oct 2014 Einat

Einat (view profile)

Thanks, saved me some work :-)

09 Sep 2014 François Beauducel

Dear John,
Yes, you missed the required version of Matlab (2014a) which contains a new function "strjoin".
I just updated the script to improve compatibility with older versions of Matlab. Please let me know.

Comment only
08 Sep 2014 John

John (view profile)

This seems to be a great tool, but I am having issues getting it to work properly. I've tried many of the examples from the help. All of them are returned with:

Undefined function 'strjoin' for input arguments of type 'cell'.

Error in dem>checkparam (line 976)
mes = sprintf('%s (%s)',mes,strjoin(val,' or '));

Error in dem (line 415)
[s,axeq] = checkparam(varargin,'axisequal',@ischar,{'auto','manual','off'});

Error in readhgt>fplot (line 395)

Error in readhgt (line 350)

Is there something I am missing?

26 Jul 2014 François Beauducel

thanks Daniel.

Comment only
25 Jul 2014 Daniel Pereira


Thank you very much for this submission.
This is an awesome tool.


16 May 2014 Greg

Greg (view profile)

Great tool, definitely useful!

I discovered one issue when downloading hgt files of North America data at all latitudes above 54°N.

On the USGS website these files are not in the * format, and are instead * (no decimal point before hgt).

Therefore line 236 in 'readhgt.m' fails for these latitudes:
k = find(~cellfun('isempty',strfind(idx{1},ff)));

I changed this line to:
k = find(~cellfun('isempty',strfind(idx{1},ff(1:end-8))));

which works, but might not be the most elegant!

Comment only
16 May 2014 Greg

Greg (view profile)

29 Nov 2013 beatrice berthelot  
30 Sep 2013 Peter Nave

Very useful tool, excellent documentation!

10 Apr 2013 Jeff

Jeff (view profile)

Regarding my previous comment, I just now noticed you recently added the 'crop' argument update which is exactly what I needed. You are way ahead of me... Amazing what a little bit of reading can do :) Thanks.

01 Aug 2012 François Beauducel

A user asked me how to extract an elevation profile from SRTM data... here is a little example (Mount Etna, Sicily):

X = readhgt(37,14:15,'merge','plot');
[x,y] = ginput(2)

then left-click on 2 different points: you will get 2 coordinates in x and y vectors. Then interpolate to create a profile vector:

xi = linspace(x(1),x(2));
yi = linspace(y(1),y(2));
zi = interp2(X.lon,,double(X.z),xi,yi);

note you need to use the DOUBLE command since SRTM elevation data are int16 class. Plot the profile on the DEM:

hold on,plot(xi,yi,'r'),hold off

Since x and y are longitudes and latitudes, the linear profile is an equirectangular approximation (rhumb line or loxodrome) of the great circle... To compute distance along this path:

di = sqrt(((xi-x(1)).*cosd(yi)).^2 + (yi-y(1)).^2)*6370*pi/180;

where cosd(yi) reduces longitude distance versus latitude, and last factor is latitude degree length in km. Then plot the profile:


that's all. If you know the profile coordinates, you don't need to use GINPUT and you directly define xi and yi with LINSPACE.

Comment only
28 May 2012 Martin Richard  
15 May 2012 François Beauducel

Thanks Warwick for your kind feedback. I'll add a 2x2 tile option, in few days.

Comment only
14 May 2012 Warwick

thank you. this is terrific, and surprisingly fast. A suggestion for a small increase in quick and easy usability would be an example of a 2by2 tile.

26 Apr 2012 1.1

- now reads also SRTM1 USA territory (1 arc-second resolution) data files.
- minor bug corrections.

14 May 2012 1.2

- adjust aspect ratio with latitude
- add minimal basemap axis ticks

18 May 2012 1.3

- adds possibility to download multiple tiles with merge option
- improved graphic output

29 May 2012 1.5

- minor modifications
- now uses DEM function (included in ZIP file) for basemap axis and legends

26 Sep 2012 1.6

Bug correction when "dem.m" function is not detected.

03 Jan 2013 1.7

- improves coding
- upgrades companion dem.m function

04 Jan 2013 1.8

minor update

21 Jan 2013 1.9

- new 'interp' option that fills the novalue gaps
- new 'crop' option to select rectangle part of tile(s)
- updated DEM companion function

23 Sep 2013 1.10

- bug correction in case of READHGT(FILENAME)
- rewriting of help
- minor corrections

19 May 2014 1.11

corrects an issue with tiles above latitude 54N (thanks to Greg).

09 Sep 2014 1.12

improve backward compatibility (strjoin)

06 Feb 2016 1.13

- 'merge' option is now default. Use new 'tiles' option to plot/download individual tiles when lat/lon are vectors
- LON argument is now automatically normalized to -180/+179°
- dem.m companion function update

06 May 2016 2.0

- new syntax readhgt(AREA)
- now can download SRTM1 30-m resolution tiles worldwide with option 'srtm1'

09 May 2016 2.1

- new options 'outdir' and 'url' (replacing former syntax)
- improves documentation

28 May 2016 2.2

- fix in AREA syntax

07 Jul 2016 2.3

- fix a problem when SRTM1 tiles are not found.

08 Jul 2016 2.4

- fix issue when merging SRTM1 tiles

Contact us