I have a large csv file (there should be about 1 million lines) with parameter data with the following structure (content changed):
secid, date, days, delta, impl_volatility, impl_strike, impl_premium, dispersion, cp_flag, ticker, index_flag, industry_group 100000, 02/05/1986, 60, -80, 0.270556, 74.2511, 5.2415, 0.021514, C, ASC, 0, 481 100000, 03/05/1986, 30, -40, 0.251556, 74.2571, 6.2415, 0.025524, P, ASC, 0, 481
I successfully imported the test file using the following:
ftest = fopen('test.csv'); C = textscan(ftest,'%f %s %f %f %f %f %f %f %s %s %f %f','Headerlines',1,'Delimiter',','); fclose(ftest);
However, C is an array of cells, and this makes it difficult to process the contents of the file in matlab. It would be easier to have it as a "regular" array (forgive me for not knowing the correct nomenclature, I just started working with Matlab).
If I go out in C, I get:
Columns 1 through 6 [2x1 double] {2x1 cell} [2x1 double] [2x1 double] [2x1 double] [2x1 double] Columns 7 through 12 [2x1 double] [2x1 double] {2x1 cell} {2x1 cell} [2x1 double] [2x1 double]
Thus, inside the cell array, which is C, there are arrays and arrays of cells - arrays for numbers and arrays of cells for strings. If I try to check element (1,2), I have to use C {1} (2), but if I want to check element (2,2), I have to use C {2} {2}. Ideally, I would like to access both C (1,2) and C (2,2). The question is, how do I do this?
I searched for solutions and found cells2mat, but it only works if all the contents are numeric (I think). I found this solution: Converting a cell array of cell arrays into a matrix matrix , but horzcat is throwing an error, which I suppose could be due to the same problem.
Thank you in advance for your time.