Prev: matlab plot
Next: better way to slice and dice
From: james bejon on 22 May 2010 19:31 Dear All, I'm hoping someone can help me out in reading some data from a csv file where: a] the first line contains the column headers, b] the first two columns contain identifiers, and c] the remaining n columns contain numbers. I want to read the first line into a cell array, the first two columns of the remaining lines into cell arrays, and the remaining entries into an array of doubles. I thought one way of doing this was to use M = dlmread(sDATA_FILE, ',', 1, 2); to read the numbers; and then I thought I could use textscan to retrieve the text identifies like this: fid = fopen(sDATA_FILE); FirstTwoColumns = textscan(fid, '%s, %s, *[^\n]'); fclose(fid); But this doesn't work, so I'm obviously misunderstanding something. James.
From: dpb on 22 May 2010 20:15 james bejon wrote: .... > to read the numbers; and then I thought I could use textscan to retrieve > the text identifies like this: > > fid = fopen(sDATA_FILE); > FirstTwoColumns = textscan(fid, '%s, %s, *[^\n]'); > fclose(fid); > > But this doesn't work, so I'm obviously misunderstanding something. I don't know what "doesn't work" means but the format string is missing the "%" before the last portion to skip to rest of line for at least one problem. --
From: james bejon on 22 May 2010 20:32 Sorry, should have been more specific. With FirstTwoColumns = textscan(fid, '%s, %s, %*[^\n]'); then, I get a (1 x 2) cell where the 1st element contains the entire first line of the csv file and the 2nd element is empty--and that's it, i.e. don't get any other lines from the file.
From: Walter Roberson on 22 May 2010 21:03 james bejon wrote: > Sorry, should have been more specific. With > > FirstTwoColumns = textscan(fid, '%s, %s, %*[^\n]'); > > then, I get a (1 x 2) cell where the 1st element contains the entire > first line of the csv file and the 2nd element is empty--and that's it, > i.e. don't get any other lines from the file. Either set the textscan Delimiter field to include comma, or use [^,] instead of %s .
|
Pages: 1 Prev: matlab plot Next: better way to slice and dice |