Code covered by the BSD License  

Highlights from
read_float.m

Be the first to rate this file! 5 Downloads (last 30 days) File Size: 2.57 KB File ID: #26646

read_float.m

by Erik Benkler

 

11 Feb 2010

Read numbers with user definable digit group and decimal separators from a text file.

| Watch this File

File Information
Description

This function reads in numbers from a text file and stores them to a cell array. It solves the problem that often the numbers in the text file are written by programs (e.g. MS Excel) using the Windows regional settings for the format of a number, e.g. 100,000.123 (english) or 100.000,123 (german). Matlab does not use windows locale settings. read_float uses either the Windows locale settings or user specified characters for the digit group and decimal separators. The numbers are detected using a regular expression which matches any floating point number (even complex numbers, see documentation of str2double.m)
The regular expression is described in a comment in the m-file and could be useful and easily adapted for similar purposes.
Using this function, there is no need to pre-process the text file, e.g. by substituting all commas by dots in a file using a comma as decimal separator.

MATLAB release MATLAB 7.0.4 (R14SP2)
Other requirements Windows OS required for using Windows regional settings, on other OS the separator characters can be provided by the user
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
decimal separator Erik Benkler 11 Feb 2010 11:48:37
digit group separator Erik Benkler 11 Feb 2010 11:48:37
regional settings Erik Benkler 11 Feb 2010 11:48:37
data import Erik Benkler 11 Feb 2010 11:48:37
locale Erik Benkler 11 Feb 2010 11:48:37
decimal separator Frank 09 Dec 2010 04:34:35

Contact us at files@mathworks.com