SimaPro
SimaPro

Reputation: 1254

How do I take the values from an array inside an array and put them into their own array?

I'm working in Octave, importing data from a CSV file (about 10^6 rows). Each row has three columns - the time stamp (in a decimal fraction of a whole day), signal 1 and signal 2. The timestamp is a double value, and I need to import it as such.

After a lot of experimentation I finally pulled out the values in double (float) format. I used the following code:

Output = textscan(FileID,'%s %f %f','Delimiter',',')

This call gave a variable of class cell that is 1x3 (note - not the 3x10^6 I expected).

Looking into the variable, I see this:

Output =
{
  [1,1] =
  {
    [1,1] = 0.85857643518518500000
    [2,1] = 0.85857648148148100000
    [3,1] = 0.85857652777777800000
    [4,1] = 0.85857657407407400000
    [5,1] = 0.85857662037037000000
    [6,1] = 0.85857665509259300000
    [7,1] = 0.85857670138888900000
    [8,1] = 0.85857674768518500000
    [9,1] = 0.85857679398148200000
    [10,1] = 0.85857684027777800000
    [11,1] = 0.85857688657407400000
    [12,1] = 0.85857693287037000000
    [13,1] = 0.85857697916666700000
    [14,1] = 0.85857702546296300000
    [15,1] = 0.85857707175925900000
    [16,1] = 0.85857711805555600000
    [17,1] = 0.85857715277777800000
    [18,1] = 0.85857719907407400000
-- less -- (f)orward, (b)ack, (q)uit

Notice it cuts off at the end but there is more data there, including the other items in the 1x3 array (namely signal 1 and signal 2).

Now - how do go from Output to MyData which should have 3 columns and a million rows of glorious data? Perhaps I import the file differently? I know I can't use dlmread or csvread because they won't let me pull in double precision numbers (unless you know a way). I have tried textread but with no luck (it told me I had a bunch of NaN's).

Upvotes: 0

Views: 35

Answers (1)

Matthew Gunn
Matthew Gunn

Reputation: 4519

Output is a cell array where each entry corresponds to one of your format codes. You might do the following:

my_strings = Output{1};
my_data = [Output{2}, Output{3}];

Small aside: the contents of a cell array can be accessed much like a normal array except you use {} instead of (). If you use () with a cell array, it returns another cell array.

Upvotes: 1

Related Questions