Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
dlmread

Subject: dlmread

From: Jessica

Date: 12 Feb, 2011 20:00:04

Message: 1 of 3

Hi,

I am trying to get a file into matlab that looks like this, delimited by spaces:


record started at: 02-12-11 11:33:08

file format version: 1
recordFrameCount movieFrameCount frames/sec QTtime(h:m:s) sysTime(h:m:s.msec) porX porY pupilX pupilY cornealRefX cornealRefY diameterW diameterH

0 43166 59.94 00:12:00 11:33:08.973 176 208 493 133 509 153 0 0
1 43167 59.94 00:12:00 11:33:09.034 176 208 493 133 509 153 0 0
2 43168 59.94 00:12:00 11:33:09.084 177 208 493 133 509 153 0 0

Two questions:
(1) Is it possible to ignore the first few lines (6 lines) of this file and only start saving into a variable starting with the numbers, i.e., "0" in this case.
(2) Matlab produces errors when I try to import the file without the headers:

0 43166 59.94 00:12:00 11:33:08.973 176 208 493 133 509 153 0 0
1 43167 59.94 00:12:00 11:33:09.034 176 208 493 133 509 153 0 0
2 43168 59.94 00:12:00 11:33:09.084 177 208 493 133 509 153 0 0

M = dlmread('data.txt','%s');

??? Error using ==> dlmread at 145
Mismatch between file and format string.
Trouble reading number from file (row 1, field 5) ==> :12:0

It seems to be having trouble with the colons.

Are there ways around these issues?

Thanks!

Subject: dlmread

From: proecsm

Date: 12 Feb, 2011 21:55:04

Message: 2 of 3

"Jessica" wrote in message <ij6os4$av3$1@fred.mathworks.com>...
> Hi,
>
> I am trying to get a file into matlab that looks like this, delimited by spaces:
>
>
> record started at: 02-12-11 11:33:08
>
> file format version: 1
> recordFrameCount movieFrameCount frames/sec QTtime(h:m:s) sysTime(h:m:s.msec) porX porY pupilX pupilY cornealRefX cornealRefY diameterW diameterH
>
> 0 43166 59.94 00:12:00 11:33:08.973 176 208 493 133 509 153 0 0
> 1 43167 59.94 00:12:00 11:33:09.034 176 208 493 133 509 153 0 0
> 2 43168 59.94 00:12:00 11:33:09.084 177 208 493 133 509 153 0 0
>
> Two questions:
> (1) Is it possible to ignore the first few lines (6 lines) of this file and only start saving into a variable starting with the numbers, i.e., "0" in this case.
> (2) Matlab produces errors when I try to import the file without the headers:
>
> 0 43166 59.94 00:12:00 11:33:08.973 176 208 493 133 509 153 0 0
> 1 43167 59.94 00:12:00 11:33:09.034 176 208 493 133 509 153 0 0
> 2 43168 59.94 00:12:00 11:33:09.084 177 208 493 133 509 153 0 0
>
> M = dlmread('data.txt','%s');
>
> ??? Error using ==> dlmread at 145
> Mismatch between file and format string.
> Trouble reading number from file (row 1, field 5) ==> :12:0
>
> It seems to be having trouble with the colons.
>
> Are there ways around these issues?
>
> Thanks!

fid = fopen('data.txt');

M = textscan(fid,'%n%n%n%s%s%n%n%n%n%n%n%n',HeaderLines,6);
fclose(fid);

Subject: dlmread

From: Jessica

Date: 12 Feb, 2011 23:17:03

Message: 3 of 3

"proecsm" wrote in message <ij6vjo$itj$1@fred.mathworks.com>...
> "Jessica" wrote in message <ij6os4$av3$1@fred.mathworks.com>...
> > Hi,
> >
> > I am trying to get a file into matlab that looks like this, delimited by spaces:
> >
> >
> > record started at: 02-12-11 11:33:08
> >
> > file format version: 1
> > recordFrameCount movieFrameCount frames/sec QTtime(h:m:s) sysTime(h:m:s.msec) porX porY pupilX pupilY cornealRefX cornealRefY diameterW diameterH
> >
> > 0 43166 59.94 00:12:00 11:33:08.973 176 208 493 133 509 153 0 0
> > 1 43167 59.94 00:12:00 11:33:09.034 176 208 493 133 509 153 0 0
> > 2 43168 59.94 00:12:00 11:33:09.084 177 208 493 133 509 153 0 0
> >
> > Two questions:
> > (1) Is it possible to ignore the first few lines (6 lines) of this file and only start saving into a variable starting with the numbers, i.e., "0" in this case.
> > (2) Matlab produces errors when I try to import the file without the headers:
> >
> > 0 43166 59.94 00:12:00 11:33:08.973 176 208 493 133 509 153 0 0
> > 1 43167 59.94 00:12:00 11:33:09.034 176 208 493 133 509 153 0 0
> > 2 43168 59.94 00:12:00 11:33:09.084 177 208 493 133 509 153 0 0
> >
> > M = dlmread('data.txt','%s');
> >
> > ??? Error using ==> dlmread at 145
> > Mismatch between file and format string.
> > Trouble reading number from file (row 1, field 5) ==> :12:0
> >
> > It seems to be having trouble with the colons.
> >
> > Are there ways around these issues?
> >
> > Thanks!
>
> fid = fopen('data.txt');
>
> M = textscan(fid,'%n%n%n%s%s%n%n%n%n%n%n%n',HeaderLines,6);
> fclose(fid);

Thanks-- this worked!

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us