No BSD License  

Highlights from
mhdrload.m

5.0

5.0 | 9 ratings Rate this file 23 Downloads (last 30 days) File Size: 5.77 KB File ID: #2973

mhdrload.m

by Jeffrey Daniels

 

27 Jan 2003 (Updated 21 Sep 2006)

Load data from an ASCII file containing multiple text headers throughout the file.

| Watch this File

File Information
Description

function [header_mat,data_mat] = mhdrload(file)
%MHDRLOAD Load data from an ASCII file containing multiple text
% headers throughout the file.
% [header, data] = MHDRLOAD('filename.ext') reads a data file
% called 'filename.ext', which contains a text header. There
% is no default extension; any extensions must be explicitly
% supplied.
%
% The first output, HEADER, is the header information, returned
% as a text array.
% The second output, DATA, is the data matrix. This data matrix
% has the same dimensions as the data in the file, one row per
% line of ASCII data in the file. If the data is not regularly
% spaced (i.e., each line of ASCII data does not contain the
% same number of points), the data is returned as a column
% vector.
%
% Limitations: No lines of the text header can begin with
% a number. The header must come before the data.
%
% MODIFIED from hdrload.m: Dec 20, 2002 Jeff Daniels, NSWCCD - ARD
% UPDATED September 20, 2006, J. Daniels
%
% See also LOAD, SAVE, SPCONVERT, FSCANF, FPRINTF, STR2MAT, HDRLOAD.
% See also the IOFUN directory.
%
% EXAMPLE:
% If example_data.txt is:
% Recorded Data: 12/15/2001
% header 1
% rows = 2 cols = 2
% 12 23
% 34 21
% header 2
% rows = 3 cols = 3
% 19 73 13
% 33 32 47
% 34 12 68
%
% MHDRLOAD returns:
% header(:,:,1) =
%
% Recorded Data: 12/15/2001
% header 1
% rows = 2 cols = 2
%
% header(:,:,2) =
%
% header 2
% rows = 3 cols = 3
%
% data(:,:,1) =
%
% 12 23 0
% 34 21 0
% 0 0 0
%
% data(:,:,2) =
%
% 19 73 13
% 33 32 47
% 34 12 68

MATLAB release MATLAB 6.0 (R12)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (10)
06 Feb 2003 Anthony McCormick

This m-file works very well. However, the first line of the data file can not have a blank line. If it does the following message is received:

??? One or more output arguments not assigned during call to 'mhdrload'.

I suggest a change to this m-file to handle blank leading lines in the input file.

Overall a very useful m-file. I highly recommend this file for everyday use.

18 Mar 2003 Eamonn Gilmartin  
16 Aug 2004 Maureen Lanan

It worked nicely.

21 Jun 2005 Jason Rupert

Very nice!

15 Jul 2005 Vipul Gupta

Helped a lot. But it takes a lot of time. Can u do something for this ?

16 Aug 2006 Richard Schaake

Great

24 May 2007 Claudio Santos

This m-file is very useful and efficient. It has helped a lot.

05 Feb 2009 Suus

Great! Does exactly what it says it does. This saved me heaps of time.

07 Jul 2009 sree reghu nathan nair  
26 Jul 2010 Jon

Great file. Easier than textread for preserving an array.

Please login to add a comment or rating.
Updates
21 Sep 2006

Updated with suggestions from user comments and M-Lint Report.

Tag Activity for this File
Tag Applied By Date/Time
data import Jeffrey Daniels 22 Oct 2008 06:56:19
data export Jeffrey Daniels 22 Oct 2008 06:56:19
load Jeffrey Daniels 22 Oct 2008 06:56:19
text Jeffrey Daniels 22 Oct 2008 06:56:19
header Jeffrey Daniels 22 Oct 2008 06:56:19
multiple Jeffrey Daniels 22 Oct 2008 06:56:19
data Jeffrey Daniels 22 Oct 2008 06:56:19

Contact us at files@mathworks.com