3.33333

3.3 | 3 ratings Rate this file 9 Downloads (last 30 days) File Size: 3.14 KB File ID: #9034
image thumbnail

Free format read - ffread.m

by Miroslav Balda

 

15 Nov 2005 (Updated 20 Jun 2007)

ffread.m is applicable for reading character information from strings or files.

| Watch this File

File Information
Description

Free-format-read function reads data of the known structure from an input, which may be either ASCII file or a string. Individual items may be numbers, words or strings. Almost any character may serve as a delimiter. The same holds even for a decimal point in real numbers. The function recognizes types of the read data. An attempt to read item after the physical end of data is signalized by returned character 127.

Forms of a call:
~~~~~~~~~~~~~~~~

 First entry:
   ffread(name);
      name = file name of the input file or string of data;
              default delimiters of items are ' ' or 'tab' 'cr' 'lf',
              default decimal point is '.'
   ffread(name,delim);
      delim = user's delimiter of items
   ffread(name,delim,point);
      point = user's decimal point character (default '.')

 Other entries:
   data = ffread;
      data = single item = number,
                    word = string without a pair of single quotes
                    string
   data = ffread(n);
      n = number of items to be read,
      data = column of n read items as
                  i. n-vector of numbers or
                  ii. n-cell array of strings
Example:
~~~~~~~~
Given the file 'test.txt' containing 6 lines:
  % Testing example for ffread
  WORD % word (string without single quotes and spaces)
  'This is a test' % string
  This is a cell array% multiple words = cell array
  123,45e-2; 1 2; 3 % ',' will be converted into '.'
  4; 5 6 % ';' will be converted into ' '

The file 'test.txt' may be read by the following script:
  ffread('test.txt', ';', ','); % file name, item delim, dec. point char.
  w = ffread; % reads word WORD into w as string
  s = ffread; % reads string into s
  c = ffread(5); % cell array of 5 words
  a = ffread; % reads one real number
  v = (ffread(6)).';% row vector v of 6 elements
  err = ffread % error! char(127) = true data already finished

MATLAB release MATLAB 7 (R14)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (3)
07 Feb 2006 Matthias D.

Works excellent on my *.ptx Laserscanner format! GREAT!!!

04 Jul 2006 basim bihnam  
10 May 2007 Emmanuel Opare  
Please login to add a comment or rating.
Updates
29 Jan 2007

Updated version v1.2 loads source file about 3x faster, tests existence of string to be read, and allows reading of numeric words by introducing a new argument.

20 Jun 2007

Improved code and help, screenshot added

Tag Activity for this File
Tag Applied By Date/Time
free format read Cristina McIntire 10 Dec 2008 16:56:57
reading character Cristina McIntire 10 Dec 2008 16:57:20
ascii Cristina McIntire 10 Dec 2008 16:57:20

Contact us at files@mathworks.com