matlab-load


load() - ignoring a given string


I am trying to use the load() function in MATLAB to read in data from a text file. However, every line of the text file ends with '...'. The data file is not produced by MATLAB, so I have no control over the source of the ellipses.
The data file I'm loading in looks something like this:
11191425 NaN NaN 0.0 ...
11191426 NaN NaN 0.0 ...
11191427 NaN NaN 0.0 ...
11191428 NaN NaN 0.0 ...
11191429 2280.5 1910.1 455.0 ...
11191430 2280.5 1910.1 455.0 ...
11191431 2298.0 1891.1 454.0 ...
11191432 2317.3 1853.7 453.0 ...
11191433 2335.6 1811.1 458.0 ...
11191434 2350.6 1769.8 466.0 ...
11191435 2365.3 1729.7 475.0 ...
11191436 2379.5 1691.2 485.0 ...
11191437 2378.3 1647.6 492.0 ...
11191438 2375.4 1621.3 499.0 ...
11191439 2372.7 1598.5 499.0 ...
11191440 2372.7 1598.5 499.0 ...
11191441 NaN NaN 0.0 ...
11191442 294.9 1283.5 1163.0 ...
11191443 294.9 1283.5 1163.0 ...
Its actual length is in excess of 100,000 rows, but you get the idea. Using the load() command throws an error because of the '...'s at the end of each line. All I'm looking for is to read in those first four columns.
What would be the most efficient way of loading the data in, whilst completely omitting the rogue column of ellipses at the end? A method that doesn't involve making the system parse the whole text file twice would be preferable, though not necessary.
This is pretty easy if instead of using load, you use textscan. You can treat that last column as a string column and then just ignore it.
fid = fopen('data.txt');
data = textscan(fid,'%d %f %f %f %s');
fclose(fid);
You could then make the output a single matrix by concatenating the columns you want to keep together.
data = [data{1:4}];
The fifth column is just filled with '...' strings. You can just ignore it.

Related Links

MATLAB - Load data file with a string file name
load() - ignoring a given string

Categories

HOME
asp.net-web-api
grok
kentico
api
delphi-7
alexa-skills-kit
flex
jelastic
devise
visual-studio-emulator
x264
jax-ws
performancepoint
g++
jxl
selenium-ide
magnetic-cards
azure-iot-hub
alpacajs
google-picker
react-toolbox
jquery-callback
dapper-extensions
intersystems-cache
sinch
event-flow
wacom
contacts
activexobject
dynamic-jasper
getpixel
yowsup
modernizr
flatmap
nohup
xv6
branching-and-merging
congestion-control
knime
jboss-4.2.x
sonarlint-eclipse
launchctl
datamaps
page-replacement
wpas
bbpress
mach-o
donations
omxplayer
myspace
np-spring
kendo-upload
asyncdisplaykit
atan2
vhosts
wiredep
mod-proxy
zscript
google-refine
git-ftp
aspectj-maven-plugin
apache-spark-1.3
viewer
ssis-data-flow
rickshaw
linkedin-jsapi
xml-namespaces
personalization
rcaller
android-framework
websphere-esb
square-bracket
multiautocompletetextview
sphinxql
c++builder-xe5
jeromq
rolify
android-icons
thttpd
usertype
denied
cgbitmapcontextcreate
presentation-layer
perl5.12
firefox-3
xslcompiledtransform
blind
image-capture
wspbuilder

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App