file .dat

file .dat

Post by Isabell » Wed, 18 Sep 2002 21:13:47

how can i read a file .dat with matlab?

file .dat

Post by Norbert Marwa » Wed, 18 Sep 2002 21:36:39

Firstly, it depends on the structure of the file. I think, it is an
ASCII file.
You can use various commands. Please look at the Matlab help for the
commands above.

1) d=load('file.dat');
???if there are only numbers in the file.

2) x=dlmread('file.dat',[1 0 20 3]);
???if you will read only the first 4 columns
???and the rows until rows 21 without the
???first row.

3) [z1 z2]=textread('file.dat','%s %s');
???if there are two columns. letters are
???allowed in the file.

4) the most generalized possibility you
???have with fopen/fgetl commands, which
???allows you to read formatted files.
clear x
while 1
??if ~ischar(s), break, end


In (1)-(3) the data in the file must be delimitered, whereas in (4)
the data must be presented in a fixed structure. All above are
examples for special numbers of columns/ rows and formatted datas,
resp., which you have to modify to your data structure. However, with
this commands you will find enough help in Matlab.


> how can i read a file .dat with matlab?
> Thanks
> Isabella