Loading ASCII tables into MATLAB as strings to be processed
Show older comments
I am working on a general script to automate plotting of selective columns and rows from large ASCII data sets.
My issue is I am having extreme difficulty loading the data into MATLAB in a way that would allow for searching through the data set. For example, an example data set may look like
- 1055+018 1 2001 Oct 19 5 6 7
- 1055+018 2 2002 Nov 21 8 9 10
- 1055+018 2 2002 Dec 12 11 12 13
- 5055+018 1 2000 Jan 10 14 15 16
- 5055+018 1 2001 Feb 11 17 18 19
- 5055+018 2 2002 Mar 12 20 21 22
I am attempting to write the code in such a way that the use could enter which item from column 1 they would want, and then the necessary rows and columns based off information found in the second row; however, due to the format of the ASCII data sets I cannot figure out a way to load data correct, even as strings, to read the whole dataset. Usually, it will just be unable to load due to the alphabetical months or cut off information depending on which loading feature I am using.
Does anyone have any suggestions on what to do?
Accepted Answer
More Answers (3)
Star Strider
on 20 Jul 2012
Edited: Star Strider
on 20 Jul 2012
This worked for me when I copy-pasted your data to a test routine:
Data = {'1055+018 1 2001 Oct 19 5 6 7'
'1055+018 2 2002 Nov 21 8 9 10'
'1055+018 2 2002 Dec 12 11 12 13'
'5055+018 1 2000 Jan 10 14 15 16'
'5055+018 1 2001 Feb 11 17 18 19'
'5055+018 2 2002 Mar 12 20 21 22'};
for k1 = 1:size(Data,1)
InputCell(k1,:) = textscan( Data{k1,:}, '%d%d %d %d %3c %d %d %d %d')
end
I got back:
InputCell =
[1055] [18] [1] [2001] 'Oct' [19] [ 5] [ 6] [ 7]
[1055] [18] [2] [2002] 'Nov' [21] [ 8] [ 9] [10]
[1055] [18] [2] [2002] 'Dec' [12] [11] [12] [13]
[5055] [18] [1] [2000] 'Jan' [10] [14] [15] [16]
[5055] [18] [1] [2001] 'Feb' [11] [17] [18] [19]
[5055] [18] [2] [2002] 'Mar' [12] [20] [21] [22]
Is that the sort of result you want? I don't use ‘textscan’ that much so others may have better solutions, but this might suggest a way for you to at least read your files. I refer you to the ‘textscan’ documentation for details.
Brendan Reardon
on 31 Jul 2012
0 votes
Brendan Reardon
on 31 Jul 2012
Categories
Find more on Large Files and Big Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!