How can I separate complex data from a .txt file?

Hello, does anyone know how to separate the data below in 6 columns? The data consists of IV-measurements of a solar cell at 166 different time units. It can be divided in 6 parts which are separated by "-marks (part 2,3 and 4 are put together between"-marks).
1;date (between "-marks)
2,3 and 4;id,temperature,irradiance(between next "-marks)
5;current measurements(between next "-marks, very large data row)
6;voltage measurements(between next "-marks, very large data row)
Thanks in advance!
"2013-11-13 08:12:33",1239169,3.9675,28.4041,"1.115000;1.117000;1.116000;1.118000;1.117000;1.117000;1.116000;1.116000;1.116000;1.120000;1.117000;1.115000;1.117000;1.117000;1.117000....etc

 Akzeptierte Antwort

Simon
Simon am 22 Nov. 2013

0 Stimmen

Hi!
It seems all your 6 fields in a row are separated with ",", right? The easiest is to read in the whole file and process each line. I used the sample line (all in one line!)
str = '"2013-11-13 08:12:33",1239169,3.9675,28.4041,"1.115000;1.117000;1.116000","1.118000;1.117000;1.117000"';
The code is
% positions of ','
ind = strfind(str, ',');
% start of each column
indstart = [1 ind+1];
% end of each column
indend = [ind-1 length(str)];
% get all columns
DateString = str(indstart(1):indend(1));
idString = str(indstart(2):indend(2));
temperatureString = str(indstart(3):indend(3));
irradianceString = str(indstart(4):indend(4));
currentString = str(indstart(5):indend(5));
voltageString = str(indstart(6):indend(6));
% convert current and voltage to numeric array
currentString = regexprep(currentString, '"', '');
currentArray = str2num(currentString);
voltageString = regexprep(voltageString, '"', '');
voltageArray = str2num(voltageString);
This can of course be done for multiple rows in the file and in vectorised form. It is just to get you started.

3 Kommentare

Bou
Bou am 22 Nov. 2013
Thank you for the comment!
Do you by any chance also know how to separate a column into several columns? The numbers are delimited by ;. I've searched on the internet but all i can find is the strsplit(...) function which i cannot use in my version of matlab.
greetings
Simon
Simon am 22 Nov. 2013
Like I did, except that you with "strfind" search for ';'. But the voltage column is already split in my example. What do you want to do with it?
Bou
Bou am 25 Nov. 2013
I figured it out. Thanks a lot!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Gefragt:

Bou
am 22 Nov. 2013

Kommentiert:

Bou
am 25 Nov. 2013

Community Treasure Hunt

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

Start Hunting!

Translated by