Importing data from a .ASC file into different columns

5 views (last 30 days)
Hello,
I am kinda getting stuck at a problem to import data form an .asc file.
Il try to clarify my problem in detail:
I have a data set (see the link,I uploaded it as txt file because attachment on this website ddnt allow ASC files to be uploaded.).
From this data set I would like to do the following thing, import it, and use data out of it. The problem is that the data is not really structured, as you can see from the link. The data is sorted in the folowing way:{Intro text}{time}{flow}{volume}{time}{flow}{volume}{time}{flow}{volume}{time}{flow}{volume}{time}{flow}{volume}{time}{flow}{volume}
This keeps going till the there are no more results. What i would like to do is to import the time data so thats the 1/4/7/10... "value" from the the attachement then put them in a column, this should be done aswell for the flow (2/5/8/11..) and for volume (3/6/9/12..). With these columns i would like to make a graph from it (i know how to do that part), but im currently stuck with importing the data and transforming each of them into a column and using regexpression to filter out the intro text.
So from the dataset (see link), this should be the "visual" result.
Time Flow Volume
1768.970 -0.010 0.077
1768.980 0.000 0.077
1768.990 0.000 0.077
1769.000 0.000 0.077
1769.010 0.000 0.077
1769.020 0.000 0.077
Currently stuck with my problem for almost 2 days, hopefully someone can help me out.
Rejiar
  1 Comment
Peter Perkins
Peter Perkins on 20 Nov 2020
This seems like a job for textscan. I'm rusty at textscan, but I think it's reasonably straight-forward. IIRC, you'd end up with a 1x3 cell array containing column vectors, which you can make a table/timetable out of as t = table(C{:});

Sign in to comment.

Answers (1)

Mathieu NOE
Mathieu NOE on 20 Nov 2020
hello
a quick and dirty code for a 3 variables file example; there is certainly room for making it more generic
hope it helps
S = fileread('y_2_2.txt');
C = regexp(S, '\s+', 'split');
ll = length(C);
variable_names = C([5 8 11]);
variable_units = C([6 9 12]);
time_data = C([16:3:ll])';
flow_data = C([17:3:ll])';
volume_data = C([18:3:ll])';

Categories

Find more on Data Type Identification in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!