Sign in

username:

password:



Not a member?

Search matlab



Search tips

Subscribe to matlab



matlab by Keywords

Atanh | Autocorrelation | Bandpass Filter | C++ | Conv | Database | Deconv | Excel | FFT | Filter | Filtering | FIR | Fourier Transfrom | FSK | Gaussian Noise | Haykin | IFFT | Image | Java | LFSR | LMS | LPC | MEX | OFDM | QPSK | Radix | Random | Sampling | Segmentation | Simulink | Visual Basic | Waveform | Wavelet

Discussion Groups

Discussion Groups | Matlab DSP | Reading text files

Technical discussion about Matlab and issues related to Digital Signal Processing.

  

Post a new Thread

Reading text files - Duroseme Taylor - Jul 23 15:10:11 2008



Hi!!

I have got a text file that I want to manipulate in matlab. The file
structure is as follows

*Extract of 060710_072827_000151.bin
Channel 1
Time: 07:28:27
Start: 381081.8 microseconds
Shows 545.6 microseconds
Time between values is 0.2 Microseconds

-0.10899135230254
-0.16348702845381
-0.10899135230254
-0.16348702845381
-0.10899135230254
-0.16348702845381
-0.16348702845381
-0.16348702845381
-0.10899135230254
-0.10899135230254
-0.10899135230254
-0.16348702845381
-0.10899135230254*

What I want to be able to do is open and read it in matlab. I particularly
need the start time and the record length. I also need to be able to use the
values just like as in a variable. So far I have tried:

   - The load command but I get this error "??? Error using ==> load Number
   of columns on line 1 of ASCII file \\tsclient\G\CG
   Flashes\060710_072624_000028\1st_stroke.txt must be the same as previous
   lines."
   - I also tried to import the data but then I get no data or I have to
   change the number of header lines and that is too long
   - Finally I tried the fopen and fscanf but still I am unable to
   accomplish what I want.

I want to open the file grab the start time and record length and save them
into variables. And then I want to grab the data-values and save that into
an array. Any help will do. Thank you
Duro
-- 
"Keep away from people who try to belittle your ambitions. Small people
always do that, but the really great ones make you feel that you too, can
become great."
Mark Twain



(You need to be a member of matlab -- send a blank email to matlab-subscribe@yahoogroups.com )

Re: Reading text files - sjoh...@cnbc.cmu.edu - Jul 24 10:48:59 2008

Hi Duro,
   You can use textread to do this. To get the data values alone in a
numerical array , try this -

X = textread('<yourtextfile>','%f','headerlines',7) ; %this skips the
first 7 text lines.

To get all the contents of the file, you can read into a cell array of
string , one line in each cell and then manipulate the cell array for
further information -

C = textread('<yourtextfile>','%s','delimiter','\n');

FOr further information, do help textread on the matlab prompt.

~S
> Hi!!
>
> I have got a text file that I want to manipulate in matlab. The file
> structure is as follows
>
> *Extract of 060710_072827_000151.bin
> Channel 1
> Time: 07:28:27
> Start: 381081.8 microseconds
> Shows 545.6 microseconds
> Time between values is 0.2 Microseconds
>
> -0.10899135230254
> -0.16348702845381
> -0.10899135230254
> -0.16348702845381
> -0.10899135230254
> -0.16348702845381
> -0.16348702845381
> -0.16348702845381
> -0.10899135230254
> -0.10899135230254
> -0.10899135230254
> -0.16348702845381
> -0.10899135230254*
>
> What I want to be able to do is open and read it in matlab. I particularly
> need the start time and the record length. I also need to be able to use
> the
> values just like as in a variable. So far I have tried:
>
>    - The load command but I get this error "??? Error using ==> load
> Number
>    of columns on line 1 of ASCII file \\tsclient\G\CG
>    Flashes\060710_072624_000028\1st_stroke.txt must be the same as
> previous
>    lines."
>    - I also tried to import the data but then I get no data or I have to
>    change the number of header lines and that is too long
>    - Finally I tried the fopen and fscanf but still I am unable to
>    accomplish what I want.
>
> I want to open the file grab the start time and record length and save
> them
> into variables. And then I want to grab the data-values and save that into
> an array. Any help will do. Thank you
> Duro
> --
> "Keep away from people who try to belittle your ambitions. Small people
> always do that, but the really great ones make you feel that you too, can
> become great."
> Mark Twain
>



(You need to be a member of matlab -- send a blank email to matlab-subscribe@yahoogroups.com )

Re: Reading text files - marc...@gmail.com - Jul 28 15:42:39 2008

All!!

Thanks for all the input. In case anyone has the same questions the solution is below. 

for i=1:3;
    dummy = fgetl(fid);
end

dummy = fgetl(fid);
start = textscan(dummy,'%*s %n');
start = start{1,1};

dummy = fgetl(fid);
lenX = textscan(dummy,'%*s %n');
lenX = lenX{1,1};

time=start:0.2:start+lenX;

X = textread(fname,'%f','headerlines',7);

Again thanks.

Hi!!
>
>I have got a text file that I want to manipulate in matlab. The file
>structure is as follows
>
>*Extract of 060710_072827_000151.bin
>Channel 1
>Time: 07:28:27
>Start: 381081.8 microseconds
>Shows 545.6 microseconds
>Time between values is 0.2 Microseconds
>
>-0.10899135230254
>-0.16348702845381
>-0.10899135230254
>-0.16348702845381
>-0.10899135230254
>-0.16348702845381
>-0.16348702845381
>-0.16348702845381
>-0.10899135230254
>-0.10899135230254
>-0.10899135230254
>-0.16348702845381
>-0.10899135230254*
>
>What I want to be able to do is open and read it in matlab. I particularly
>need the start time and the record length. I also need to be able to use the
>values just like as in a variable. So far I have tried:
>
>   - The load command but I get this error "??? Error using ==>  load Number
>   of columns on line 1 of ASCII file \\tsclient\G\CG
>   Flashes\060710_072624_000028\1st_stroke.txt must be the same as previous
>   lines."
>   - I also tried to import the data but then I get no data or I have to
>   change the number of header lines and that is too long
>   - Finally I tried the fopen and fscanf but still I am unable to
>   accomplish what I want.
>
>I want to open the file grab the start time and record length and save them
>into variables. And then I want to grab the data-values and save that into
>an array. Any help will do. Thank you
>Duro
>-- 
>"Keep away from people who try to belittle your ambitions. Small people
>always do that, but the really great ones make you feel that you too, can
>become great."
>Mark Twain



(You need to be a member of matlab -- send a blank email to matlab-subscribe@yahoogroups.com )