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:
textscan to read txt files

Subject: textscan to read txt files

From: Mathew Thomas

Date: 9 Mar, 2012 23:27:32

Message: 1 of 2

Hello All,

I have a txt file that has the following kind of data (after the headerlines, that I have not copied here):


Packet # 1, intensity = 4.548799, mass/position = 150.166667
saturated = 0, fragmented = 0, merged = 0

Packet # 2, intensity = 34.496151, mass/position = 150.250000
saturated = 0, fragmented = 0, merged = 0

Packet # 3, intensity = 57.512409, mass/position = 150.333333
saturated = 0, fragmented = 0, merged = 0

----------------------------------------------------------------------------------------------------------------

I need to get the intensity and mass/position values out of the file.
For ex, I need to get
4.548799 150.1666667
34.496151 150.25
57.512409 150.33


What is the correct way to do this ?

Right now I use textscan like this:
C = textscan(fid, '%*s %*s %*s %*s %*s %s %s %*s %*s %*s', 'Delimiter', 'White space', 'Headerlines',36);
and then a loop to get rid of the lines I do not need.

Even after doing that, I get cell arrays with a comma:
4.548799,
34.496151,
57.512409,


Thank you,

Mathew

Subject: textscan to read txt files

From: oops

Date: 21 Mar, 2012 12:12:11

Message: 2 of 2

Hello

I have a question related with textscan also. I have to read a huge file which is divided in several parts, each of them corresponds to a different kind of data and the information of each block is different:
% coments
100135 'cucu' 5.00 3 9.0 10.80 101 110 .98750 -56.0361 100
135 'pepito' -5.00 2 7.0 1.80 98 40 0.860 6.0361 -150
% coments
100417 'A' 11.0 0.0 -7.56 4.13 0.43185 0 1.5 9.0080 5.15 0.0 9.0 1.13 0 -1.04 11.34 1.45 16 1.00
I know the number of lines of each block, so for example I write:

data1=textscan(f,'%d%s%n%d%n%n%d%d%n%n%d',3, 'Delimiter',' ,;\t','MultipleDelimsAsOne',true, 'Headerlines',1,'EmptyValue',nan);

data2=textscan(f,'%d%s%n%n%n%n%n%d%n%n%n%n%n%n%d%n%n%n%d%n%d%n%d%n%d%n',2, 'Delimiter',' ,;\t','MultipleDelimsAsOne',true, 'Headerlines',1,'EmptyValue',nan);

I do not really know if I am doing it well, or not because I cannot print the results I obtain it sais
data1: {1x11 cell}
data2: {1x26 cell}

I am reading two lines for data1, why it is 1x11? how can I and use the data I read?

Thank you

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