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:
read in matrix from .dat file

Subject: read in matrix from .dat file

From: Alex

Date: 16 Aug, 2011 21:15:30

Message: 1 of 4

I have been looking around the newsreader as well as other search engines for an answer to a problem I'm having, but haven't had any luck.
I have a camera that records data as a .sif file, and exports it as a .dat file. The video has a resolution of 512x512, is 600 frames in length, and the file size is 300MB. It may be exporting the video as a 307200x514 array (it adds a column of padding to both sides of the array, and stacks the frames together as rows ), but I'm not sure as I cant get the file open. It should be a space delimited file containing only numbers representing intensities on the camera, no text. My question is how to read the .dat file into matlab as an array.
I have tried:

A = fread('new02z.dat')
A = fopen('new02z.dat');
A = fopen('new02z.dat','r')
fid = ('new02z.dat')
A = fread(fid, [307200,514]);
A = textread('new02z.dat');
A = dlmread('new02z.dat',' ');
A = dlmread('new02z.dat',' ',0,0);
and the import data wizard.

all either imported a single digit, or returned error messages to which I have not found a solution for.
I am running 7.11.0 R2010b if that helps.

Thanks,
Alex

Subject: read in matrix from .dat file

From: Steven_Lord

Date: 16 Aug, 2011 21:32:09

Message: 2 of 4



"Alex " <blue.harvest.83@gmail.com> wrote in message
news:j2emli$k4a$1@newscl01ah.mathworks.com...
> I have been looking around the newsreader as well as other search engines
> for an answer to a problem I'm having, but haven't had any luck.
> I have a camera that records data as a .sif file, and exports it as a .dat
> file. The video has a resolution of 512x512, is 600 frames in length, and
> the file size is 300MB. It may be exporting the video as a 307200x514
> array (it adds a column of padding to both sides of the array, and stacks
> the frames together as rows ), but I'm not sure as I cant get the file
> open. It should be a space delimited file containing only numbers
> representing intensities on the camera, no text. My question is how to
> read the .dat file into matlab as an array. I have tried:
>
> A = fread('new02z.dat')

FREAD is documented to accept a file identifier (as returned by FOPEN) not a
file _name_.

http://www.mathworks.com/help/techdoc/ref/fread.html

> A = fopen('new02z.dat');

This creates a file identifier that you can use with the low-level file I/O
functions like FREAD to retrieve the data. It does NOT retrieve the data
itself.

http://www.mathworks.com/help/techdoc/ref/fopen.html

Use this THEN use FSCANF, FREAD, TEXTSCAN, etc. [Actually since your file is
plain text, FREAD doesn't seem like the right tool. Try FSCANF or TEXTSCAN
first.]

http://www.mathworks.com/help/techdoc/ref/textscan.html

*snip*

> all either imported a single digit, or returned error messages to which I
> have not found a solution for.

FYI, the group will find it MUCH easier to help you interpret error messages
if you post the full text of the message as well as the code you executed to
generate the error.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: read in matrix from .dat file

From: TideMan

Date: 16 Aug, 2011 22:29:50

Message: 3 of 4

On Aug 17, 9:15 am, "Alex " <blue.harvest...@gmail.com> wrote:
> I have been looking around the newsreader as well as other search engines for an answer to a problem I'm having, but haven't had any luck.
> I have a camera that records data as a .sif file, and exports it as a .dat file.  The video has a resolution of 512x512, is 600 frames in length, and the file size is 300MB.  It may be exporting the video as a 307200x514 array (it adds a column of padding to both sides of the array, and stacks the frames together as rows ), but I'm not sure as I cant get the file open.  It should be a space delimited file containing only numbers representing intensities on the camera, no text.  My question is how to read the .dat file into matlab as an array.  
> I have tried:
>
> A = fread('new02z.dat')
> A = fopen('new02z.dat');
> A = fopen('new02z.dat','r')
> fid = ('new02z.dat')
> A = fread(fid, [307200,514]);
> A = textread('new02z.dat');
> A = dlmread('new02z.dat',' ');
> A = dlmread('new02z.dat',' ',0,0);
> and the import data wizard.
>
> all either imported a single digit, or returned error messages to which I have not found a solution for.
> I am running 7.11.0 R2010b if that helps.
>
> Thanks,
> Alex

Unless you find out for sure what the format is, you've got no hope.
This " It may be exporting the video as a 307200x514 array" is not
good enough.
And what is "a column of padding"? Is it an extra comma at the front
and end of each line? Or what?

One way to check all this is:
fid =fopen('new02z.dat','rt');
line=fgetl(fid)
This will give you the first line in the file and from that you can
figure out what to do next.

Here's a guess at what you need
frewind(fid); % Need to rewind after fgetl
c=textscan(fid,repmat('%f',514,1),20);
which will read the first 20 lines, assuming the delimiter is space.

Subject: read in matrix from .dat file

From: Loren

Date: 19 Apr, 2013 23:43:10

Message: 4 of 4

"Alex " <blue.harvest.83@gmail.com> wrote in message <j2emli$k4a$1@newscl01ah.mathworks.com>...
> I have been looking around the newsreader as well as other search engines for an answer to a problem I'm having, but haven't had any luck.
> I have a camera that records data as a .sif file, and exports it as a .dat file. The video has a resolution of 512x512, is 600 frames in length, and the file size is 300MB. It may be exporting the video as a 307200x514 array (it adds a column of padding to both sides of the array, and stacks the frames together as rows ), but I'm not sure as I cant get the file open. It should be a space delimited file containing only numbers representing intensities on the camera, no text. My question is how to read the .dat file into matlab as an array.
> I have tried:
>
> A = fread('new02z.dat')
> A = fopen('new02z.dat');
> A = fopen('new02z.dat','r')
> fid = ('new02z.dat')
> A = fread(fid, [307200,514]);
> A = textread('new02z.dat');
> A = dlmread('new02z.dat',' ');
> A = dlmread('new02z.dat',' ',0,0);
> and the import data wizard.
>
> all either imported a single digit, or returned error messages to which I have not found a solution for.
> I am running 7.11.0 R2010b if that helps.
>
> Thanks,
> Alex

Try simply load('new02z.dat');

Tags for 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