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 http://www.mathworks.com/company/newsletters/news_notes/dec04/cleanup.html. 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 http://www.mathworks.com/company/newsletters/digest/nov04/newfeatures.html?mld_na_tech2.

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
,-5.00E+00,-4.00E+00,-3.00E+00,-2.00E+00,...
1.00E+00,6.19E-07,8.63E-07,6.43E-07,1.84E-07,...
2.00E+00,2.88E-07,4.71E-07,6.92E-07,1.43E-07,...
3.00E+00,2.52E-07,8.11E-07,4.74E-07,8.48E-07,...
4.00E+00,...
...

*       Mobile2
*       SNR Vs test No
Num tests=20
,-5.00E+00,-4.00E+00,-3.00E+00,-2.00E+00,-1.00E+00,0.00E+00,...
1.00E+00,6.19E-07,8.63E-07,6.43E-07,1.84E-07,6.86E-07,3.73E-,...
2.00E+00,...
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 =
19

InputText=textscan(fid, '%f', 'delimiter', ','); % Read data block
Data=reshape(InputText{1},[],NumCols)';
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.

hohonuuli

Developer

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

0 comments: