MATLAB Answers

Loen
0

How to import data with different structures

Asked by Loen
on 14 Nov 2013
Hello,
I've a whole bunch of datafiles existing of text and tables. These files are filled automatically with measurement data and because of this the size is different for each file.
I want to import the data to analyze and plot the content of the different tables.
At the moment I use textscan and load the file in one cell...
[name, pathname] = uigetfile('*.log');
filename = cat(2, pathname, name);
delimiter = '\t';
formatSpec = '%s%[^\n\r]';
fileID = fopen(filename,'r');
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'MultipleDelimsAsOne', true, 'EmptyValue' ,NaN, 'ReturnOnError', false);
fclose(fileID);
Data = dataArray{:, 1};
clearvars delimiter formatSpec fileID dataArray ans;
Then find the beginning and end of each table with strcmp
Q = strcmp('qqqqqq', Data);
x = strcmp('xxxxxx', Data);
Then reload the data again with textscan with begin and end row defined as Q and X and load the content of the table into double and cells (depends on the content). This is repeated for all tables .
My question: I'm sure there's a easier and less time-consuming process but I don't know how. Could someone explain to me what's the best way to handle this kind of logfiles
best regards, loen

  0 Comments

Sign in to comment.

0 Answers