Matlab data extracting

  • MATLAB
  • Thread starter ironcross77
  • Start date
  • #1
Ok I have a .dat file containing these datas:


_________________________________________________________________
Date and Time : 120106 12:31:32 12:31:39
Location: 1509123
Bearing: 135
Angle : 30

Scan No. Coordinates PhotonCount
255 12 1
255 45 32
255 34 1231
255 21 54321
255 24 1231

______________________________________________________________


So, you can see that the file contains an array containing three coloums.

I want to extract these three coloums into an array using MATLAB

Can someone write an .m file that will do the job ?

Thank You
 

Answers and Replies

  • #2
uart
Science Advisor
2,784
12
Just edit the text file so that it contains only the 3 columns of data and nothing else and then give this file some name, say tmp.dat. Then just load it into matlab using "load tmp.dat".

This will create a matrix called "tmp" in matlab that contains all three columns of data. Then extract each column to a vector using "x=tmp(:,1)", "y=tmp(:,2)" etc.
 
  • #3
I have more than 2000 of such files. It cannot be done manually.
I need matlab to automatically to do it.
 
  • #4
jim mcnamara
Mentor
4,362
3,016
ironcross77 said:
I have more than 2000 of such files. It cannot be done manually.
I need matlab to automatically to do it.

FWIW - if you are working in any flavor of UNIX the text editing capabilities can do what you want in:
Code:
for file in `ls /path/to/files/*.dat`
do
       sfile=`basename $file`
       grep -v -e Date -e Scan -e Loca -e Bear $file > /new/path/$file
done

All that's left = columns of numbers... in 2000 new files. The old ones are not changed.
 
  • #5
krab
Science Advisor
893
2
Just use fscanf; intitally call it once for each of the first 6 lines, then use it once more to read the 3 columns into a matrix.
 
  • #6
1,356
2
create save and load functions...so that the save will emulate the structure of the files that you have...then create teh load function based off the save function and you should eb able to extract all information adn then leave out the ones you want.
 
  • #7
thanks everybody
 

Related Threads on Matlab data extracting

Replies
1
Views
963
Replies
6
Views
7K
Replies
8
Views
3K
Replies
1
Views
3K
Replies
2
Views
3K
  • Last Post
Replies
15
Views
1K
  • Last Post
Replies
9
Views
3K
Replies
1
Views
20K
Replies
2
Views
1K
Top