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:
Data analysis of data from txt file

Subject: Data analysis of data from txt file

From: Hans Addington

Date: 30 Jul, 2014 12:21:14

Message: 1 of 1


Hi

I have a txt file with the following columns with n rows:

18-03-2014 12:54:19 19.9 48.1 23.4 1002.3
18-03-2014 12:54:24 19.8 48.1 23.4 1002.3
18-03-2014 12:54:29 19.8 48.1 23.4 1002.3
18-03-2014 12:54:34 19.8 48.1 23.4 1002.3
18-03-2014 12:54:39 19.8 48.3 23.3 1002.3
18-03-2014 12:54:44 19.8 48.3 23.3 1002.3
18-03-2014 12:54:49 19.8 48.3 23.3 1002.3

I want to write the date-time string and column 2 to a new txt file that should look like:

18-03-2014 12:54:19 19.9
18-03-2014 12:54:24 19.8
18-03-2014 12:54:29 19.8
18-03-2014 12:54:34 19.8
18-03-2014 12:54:39 19.8
18-03-2014 12:54:44 19.8
18-03-2014 12:54:49 19.8

How should I do this? I tried the following:

fid = fopen(data.txt');
dateItem = [];
values = [];
while ~feof(fid)
[dateItem]= [dateItem ; fscanf(fid,'%s',2)];
[values]= [values ;fscanf(fid,'%f %f %f %f',4)'];
end
fclose(fid);

It will give me a date-time string and the numeric data in the array named values.
The date-time string is wrote because it write 18-03-201412:54:19 instead of 18-03-2014 12:54:19.

Best Regards

Tags for this Thread

No tags are associated with 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