Does 'colheaders' require a minimum array size?

I have a peice of code that graphs data, and I use the values stored in 'colheaders' from importing to lable the graphs. In copying the code I discovered that if I have fewer than 1255 data points - the 'colheaders' attribute completely disappears i.e. if I have >1255 data points my file imports a structure with:
data < double >, textdata < cell >
But if I have >1255 data points my file returns a structure with:
data < double >, textdata < cell >, colheaders < cell >
I identified the 1255 min by trial and error i.e. literally just changing the size of the array I was importing, I've also tried adding the '\t' or tab delimiter identifier in my 'importdata' with no luck.
Any ideas on how to create the variable colheaders without having a minimum number of data points? Or more likely, any ideas on what I'm doing wrong as it seems crazy to have a data min restraint here.
Thanks in advance!

Réponses (1)

per isakson
per isakson le 6 Juin 2012
R2012a. I'm lucky with the example from the on-line help. I copy&paste
Day1 Day2 Day3 Day4 Day5 Day6 Day7
95.01 76.21 61.54 40.57 5.79 20.28 1.53
23.11 45.65 79.19 93.55 35.29 19.87 74.68
60.68 1.85 92.18 91.69 81.32 60.38 44.51
48.60 82.14 73.82 41.03 0.99 27.22 93.18
89.13 44.47 17.63 89.36 13.89 19.88 46.60
to the file: ascii_with_colhead.txt
>> A = importdata( 'ascii_with_colhead.txt')
A =
data: [5x7 double]
textdata: {'Day1' 'Day2' 'Day3' 'Day4' 'Day5' 'Day6' 'Day7'}
colheaders: {'Day1' 'Day2' 'Day3' 'Day4' 'Day5' 'Day6' 'Day7'}
What does the field textdata contain with the small file? It is hard for us to understand exactly how you use importdata.
The import data wizard (invoked by the icon in the workspace toolbar) returns the same data, but in three separate variables.
--- More ---
If importdata does not recognize the first column as numbers it will not return colheaders. The text is however included in textdata.

4 commentaires

Natasha
Natasha le 7 Juin 2012
Hi Per, thanks for such a quick response.
I followed your example above and my results exactly mimic yours; everything looks fine there.
If you use the attached two files; MarketDataRatio_SPX_IG is almost identical to MarketDataRatio_SPX_HYspd except it has 3 data columns instead of 4, and only 350 data points instead of >1000 in MarketDataRatio_SPX_HYspd.
If you use the import wizard directly - it does not import colheaders for either function, it seems to default to replacing text values with '0'.
If I call importdata as a function - the SPX_IG file does not create a colheaders variable, but the SPX_HYspd file does.
Figuring out how to attach a file...
Walter Roberson
Walter Roberson le 7 Juin 2012
http://www.mathworks.com/matlabcentral/answers/7924-where-can-i-upload-images-and-files-for-use-on-matlab-answers
Natasha
Natasha le 7 Juin 2012
Thank you Walter, didn't realize file exchange was how I was supposed to upload. Thanks!
Walter Roberson
Walter Roberson le 7 Juin 2012
The file exchange is not the way to upload: use one of the commercial servers and post the URL.

Connectez-vous pour commenter.

Question posée :

le 6 Juin 2012

Community Treasure Hunt

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

Start Hunting!

Translated by