Loading ASCII tables into MATLAB as strings to be processed
古いコメントを表示
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?
採用された回答
その他の回答 (3 件)
Star Strider
2012 年 7 月 20 日
編集済み: Star Strider
2012 年 7 月 20 日
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
2012 年 7 月 31 日
カテゴリ
ヘルプ センター および File Exchange で Large Files and Big Data についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!