Domanda

I'm having a rough time trying to import this data in matlab using code (not using the "Variable -> Import Data" feature) because of the format of the file. I really can't think of a solution using the usual loading commands and not involving editing the file. I have tried using

data=dlmread(File, '\t', [27 0 7865 9]); % 27 is the starting row and 7865 the ending row for the first set data

which should work according to me, but it stops loading the data in row 2400 aproximately (the time variable is 58 and it should end around 200) without any apparent reason. I would appreciate very much a little guidance!

another problem is that the data is arranged in this way

garbage 
...
time1 data1 time2 data2 ...
time11data11...

and when the time variable starts using 6 digits (e.g. 100.025) there starts to cease the existance of whitespace between the data points, so any separator like a space will not be recognized in this case. For example,

108.900 -0.000108.905 -0.005108.910 -0.006108.915 -0.006108.920 -0.003

means

108.900 -0.000 108.905 -0.005 108.910 -0.006 108.915 -0.006 108.920 -0.003

This is so because the data has 3 decimals.

Any hints will help.

È stato utile?

Soluzione

I think you would need to read line by line your input data, and use regexp on the lines with numbers you want, examples are given:

% regular pattern to read your numbers. This is constructed based on the
% example data file you provided.
regPattern = '-?\d{1,3}\.\d{3}';

% example of nicely separated values:
s1 = '  0.100  0.000  0.105 -0.000  0.110 -0.000  0.115  0.000  0.120 -0.000';    
r1 = regexp(s1, regPattern, 'match');

% example of non-separated values:
s2 = '108.900 -0.000108.905 -0.005108.910 -0.006108.915 -0.006108.920 -0.003';    
r2 = regexp(s2, regPattern, 'match');

The results are:

r1 = 

    '0.100'    '0.000'    '0.105'    '-0.000'    '0.110'    '-0.000'    '0.115'    '0.000'    '0.120'    '-0.000'


r2 = 

    '0.100'    '0.000'    '0.105'    '-0.000'    '0.110'    '-0.000'    '0.115'    '0.000'    '0.120'    '-0.000'
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top