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
shell
google-app-engine
beautifulsoup
pascal
components
saml-2.0
package
nsbundle
rom
settings
android-json
gluon-mobile
webix
odoo-8
plink
heat
dynamic-sql
feathersjs
nodemcu
highstock
beta
xunit
moses
surveymonkey
inversion-of-control
rselenium
github3.py
installshield-le
searchkit
lint
demo
spring-mvc-test
magento-1.9.3
vmware-fusion
subclipse
vaadin-elements
clarifai
avx
skin
check-mk
java-websocket
offline.js
gameplay-kit
juice-ui
reachability
taocp
smartfoxserver
pacemaker
microstation
spring-cloud-feign
mapinfo
riot
aurora
lz77
beanstalk
realsense
blitline
grgit
uncompress
baasbox
skspritenode
telepat
qtwebengine
cross-join
nodelist
viewer
cbind
named-parameters
template-deduction
grails-domain-class
tinyxml
decoupling
away3d
tlf
composite-component
veracity
procedures
jquery-tools
twitterizer
cac
easyb
message-passing
cfwindow
strtod
tui
cuda.net
fault-tolerance

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