Reading certain parts of text file

Hi,
I'm trying to access certain parts of a text to process data. The text file has a header and many rows of numbers, starting at lines 13 through 4016 is a two column array. This is comma delimited. It would be nice to track information of this file located in the header but firstly I just want to bring all of these numbers into Matlab for processing. The formats don't change per text file just the numbers.
Thanks for your help, Alex

Antworten (1)

Azzi Abdelmalek
Azzi Abdelmalek am 13 Jan. 2014
Bearbeitet: Azzi Abdelmalek am 13 Jan. 2014

0 Stimmen

a=importdata('file.txt')
data=a.data

5 Kommentare

ALEX
ALEX am 13 Jan. 2014
Thanks for the response, I just tried this, the end result is a scalar of some number. I'm trying to produce a 40??x2 array for each file.
Azzi Abdelmalek
Azzi Abdelmalek am 13 Jan. 2014
what do you mean? and post a sample of your file
ALEX
ALEX am 13 Jan. 2014
Bearbeitet: Azzi Abdelmalek am 13 Jan. 2014
SOURCE FILE NAME: H:\Research 2013\alex pullout\c#6_6_1.DTA
DATE: Monday, July 08, 2013
TIME: 15:40:56
SAMPLE INTERVAL (Seconds): 0.0000020000
SIGNAL UNITS: volts
TIME UNITS: Seconds
DATA TYPE: WAVEFORM
NUMBER OF DATA POINTS PER WAVEFORM: 4096
CHANNEL NUMBER: 2
HIT NUMBER: 2
TIME OF TEST: 416.0837267
0, 0.00061035
1, 0.00030518
2, 0.00000000
3, -0.00030518
4, -0.00061035
5, 0.00000000
6, -0.00030518
7, 0.00000000
8, 0.00000000
9, 0.00030518
10, 0.00061035
11, 0.00061035
12, 0.00091553
13, 0.00061035
14, 0.00061035
15, 0.00000000
16, 0.00000000
17, 0.00030518
Azzi Abdelmalek
Azzi Abdelmalek am 13 Jan. 2014
Bearbeitet: Azzi Abdelmalek am 13 Jan. 2014
fid=fopen('file.txt')
out=textscan(fid,'%f %f','HeaderLines',12,'Delimiter',',')
fclose(fid)
M=cell2mat(out)
ALEX
ALEX am 13 Jan. 2014
Bearbeitet: Azzi Abdelmalek am 13 Jan. 2014
I figured it out, there is a special function that does all of this hands free.
num = csvread(filename,13,0)
this data is already comma delimited, so I could open it as a txt file without any problems. If there aren't commas it might not be so easy.
this youtube video was helpful.

Melden Sie sich an, um zu kommentieren.

Produkte

Gefragt:

am 13 Jan. 2014

Bearbeitet:

am 13 Jan. 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by