by 2/02/2005 03:19:00 PM 0 comments

New Matlab featues

There are 2 handy new features in Matlab 7.0. The first is mlint, an m-file similar to C's lint that checks the code for style, language usage and portability. Mathworks has an article about it at The second handy feature is the new textscan function which really simplifies access to data in arbirarily formatted text files. Here's some info from an article on

Text File Reading

The new textscan function enables you to access very large text files that have arbitrary format. This function is similar to textread but adds the ability to specify a file identifier so that a file pointer can be tracked and traversed through the file. The file can therefore be read a block at a time, changing the format on each occasion. For example, suppose we have a text file, test12_80211b.txt, which contains multiple different-sized blocks of data, each with the following format:
  • Two headerlines of description
  • A parameter m
  • A p x m table of data
Here is how test12_80211b.txt looks:
*       Mobile1
*       SNR Vs test No
Num tests=19

*       Mobile2
*       SNR Vs test No
Num tests=20
You could use the following MATLAB commands to read it in:
fid = fopen('test12_80211b.txt', 'r'); % Open text file
InputText = textscan(fid, '%s', 2, 'delimiter', '\n'); % Read header lines
HeaderLines = InputText{1} HeaderLines =
'* Mobile1'
'* SNR Vs test No'

InputText = textscan(fid, 'Num tests=%f'); % Read parameter value
NumCols=InputText{1} NumCols =

InputText=textscan(fid, '%f', 'delimiter', ','); % Read data block
format short g
Section=Data(1:5,1:5) Section =
NaN 	-5 	-4 	-3 	-2
1 	6.19e-007 	8.63e-007 	6.43e-007 	1.84e-007
2 	2.88e-007 	4.71e-007 	6.92e-007 	1.43e-007
3 	2.52e-007 	8.11e-007 	4.74e-007 	8.48e-007
4 	1.97e-007 	1.64e-007 	1.38e-007 	6.17e-007
For improved data access speed, in this release of MATLAB the reading of comma-separated-value (CSV) files is an order of magnitude faster.

Brian Schlining


Cras justo odio, dapibus ac facilisis in, egestas eget quam. Curabitur blandit tempus porttitor. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.