Code covered by the BSD License  

Highlights from
ENVI file reader/writer

4.2 | 4 ratings Rate this file 51 Downloads (last 30 days) File Size: 7.38 KB File ID: #27172

ENVI file reader/writer



05 Apr 2010 (Updated )

Mini-toolbox for reading and writing ENVI data and header files (including complex).

| Watch this File

File Information

%test script

%clears workspace

%generate a complex 3-D variable

%create basic ENVI header info about a Matlab variable

%write the variable and the associated header info in a pair of binary/header ENVI files
enviwrite(D,info,'a.dat'); %implicit header file is "a.dat.hdr" (if not explicitly passed)

%read a complex n-D variable from "a.dat" and "a.dat.hdr" ENVI files

%some comparisons to validate consistency of our read/write procedures

%modify the header info (introducing offset in ENVI header)
D3=D2; %same as D2

%writing the D3 (same as D2), but with 10000 offset

%read the offset variable (D3)

%comparisons to validate read/write


Envi To Matlab, Matlab To Envi, Envi File Reader, Updated 2/9/2010, and Read Envihdr inspired this file.

MATLAB release MATLAB 7 (R14)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (10)
28 Jan 2015 Benjamin Carlson

envihdrread.m, lines 66, 67, and 68 need to be replaced by:
line=string_to_cell(line, ',');

With this change, the program works great, thanks!
Ben Carlson, University of Oklahoma

26 Jan 2015 Rob Cranfill

This looks awesome, thanks! Except, as YongHyun wrote, it seems to error out under 2014b. I will attempt to hack it into submission, and if successful, will contribute the solution here, forthwith.

I am not even sure what the line of code "line=textscan(line,'%s',',');" is trying to do - that doesn't seem to be legal syntax, AFAICT.

25 Dec 2014 YongHyun

There are some errors on Ver. R2014b.

Error using textscan
Name-value pair arguments must come in pairs.

Error in envihdrread (line 66)
line=textscan(line,'%s',','); %behavior is not quite the same if "line" ends in ','

Error in enviread (line 20)

Comment only
14 Aug 2014 Buwei

Buwei (view profile)

26 Jun 2013 Felix Totir

@James Wheeler: thank you for your contribution. Unfortunately, I am not able to test it, but please fork the code on the MatlabCentral. Or, if others confirm and youa gree, I will integrate it into the current code (with credit).

Comment only
25 Jun 2013 James Wheeler

I've written a few lines for envihdrread (at line 70) to allow for projections with whitespace in them (i.e. Geographic Lat/Lon). Apologies for clumsy script, I'm new to this...
if ischar(line{2})
line{2}=[line{1},' ',line{2}];
for n=1:numel(line)-1
line(numel(line))=[] ;

Comment only
22 Aug 2012 Benjamin

writeenvi.m produces error: Undefined function 'fix' for input arguments of type 'struct' in num2str using version 7.14(2012A).

Comment only
18 Jan 2012 Felix Totir

@Jaroslaw Tuszynski: The provided function envidataread.m is esentially a wrapper around multibandread(). Even a hint towards multibandread is given in the comments on lines 88 and 90 of that function (please have a look at the code).

However, using multibandread alone requires *reading the header by a human*. The purpose of this little toolbox is exactly to automatize that operation (working with headers and data).

Comment only
18 Jan 2012 Jaroslaw Tuszynski

A better option is to use MATLAB's multibandread function

Comment only
30 Nov 2010 Margaret

Very useful for importing ENVI standard files into Matlab as well as outputing the results from a Matlab analysis back to ENVI! Runs fast - no compatibility issues with large files.

26 Jul 2010

improved description

Contact us