{
  "id": 11221,
  "title": "Reading data in MATLAB",
  "url": "/competitions/avazu-ctr-prediction/discussion/11221",
  "author_name": "",
  "post_date": "2014-12-13T01:26:23.597Z",
  "votes": null,
  "comment_count": 4,
  "views": 1631,
  "content": "<p>How to read this data in MATLAB? csvread doesn't work!</p>",
  "messages": [
    {
      "id": "60126",
      "postDate": "12/13/2014 01:26:23",
      "content": "<p>How to read this data in MATLAB? csvread doesn't work!</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "60140",
      "postDate": "12/13/2014 10:42:15",
      "content": "<p>just try these MATLAB API :</p>\n<p>fid = fopen('path/filename.csv') ;</p>\n<p>dcells = textscan(fid, 'your-format-string' , 'Delimiter', ',', 'Headerlines', 1 &nbsp;) ;</p>\n<p>fclose(fid) ;</p>\n<p>Them ,all data have been load in dcells .</p>\n<p>good luck ~</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "60165",
      "postDate": "12/13/2014 23:09:30",
      "content": "<p>Thanks!&nbsp;</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "60166",
      "postDate": "12/13/2014 23:27:26",
      "content": "<p>Or better yet, use the new datastore feature in R2014b. See the example code below.&nbsp;</p>\n<p>Cheers!</p>\n\n<p>%% Avazu Example Datastore Code</p>\n<p>ftrain = 'train.csv';</p>\n<p>% Create datastore object to perform partial data reads</p>\n<p>ds = datastore(ftrain);</p>\n<p>% Define data formats for each variable</p>\n<p>% variables removed from new dataset: device_os, device_make, device_geo_country</p>\n<p>ds.SelectedFormats = {'%q'... % id</p>\n<p>'%d'... % click</p>\n<p>'%d'... % hour</p>\n<p>'%C'... % C1</p>\n<p>'%C'... % banner_pos</p>\n<p>'%C'... % site_id</p>\n<p>'%C'... % site_domain</p>\n<p>'%C'... % site_category</p>\n<p>'%C'... % app_id</p>\n<p>'%C'... % app_domain</p>\n<p>'%C'... % app_category</p>\n<p>'%q'... % device_id - ignore</p>\n<p>'%q'... % device_ip - ignore</p>\n<p>'%C'... % device_model</p>\n<p>'%C'... % device_type</p>\n<p>'%C'... % device_conn_type</p>\n<p>'%C'... % C14</p>\n<p>'%C'... % C15</p>\n<p>'%C'... % C16</p>\n<p>'%C'... % C17</p>\n<p>'%C'... % C18</p>\n<p>'%C'... % C19</p>\n<p>'%C'... % C20</p>\n<p>'%C'}; % C21</p>\n\n<p>%% Read in all of the click variable</p>\n<p>ds.SelectedVariableNames = 'click';</p>\n<p>click = readall(ds);</p>\n<p>click = logical(click.click);</p>\n<p>%% Partial reads to sample</p>\n<p>% Read in first row to initialize table variable</p>\n<p>ds.RowsPerRead = 1;</p>\n<p>data = read(ds);</p>\n<p>% Reset number of rows per read</p>\n<p>ds.RowsPerRead = 20000;</p>\n<p>% Read in a block and process</p>\n<p>while hasdata(ds)</p>\n<p>tempdata = read(ds);</p>\n<p>% Pull random sample without replacement</p>\n<p>tempdata = datasample(tempdata,100,'Replace',false);</p>\n\n<p>data = [data; tempdata];</p>\n<p>end</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "60168",
      "postDate": "12/13/2014 23:47:26",
      "content": "<p>Textscan doesnt seem to work because data doesn't fit in memory. Also, datastore isn't present in R2014a, which is the version of MATLAB I am using.</p>\n<p>Any solution to this data problem?</p>",
      "rawMarkdown": "",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 60140,
      "author_name": "lemoner",
      "author_url": "",
      "post_date": "12/13/2014 10:42:15",
      "content": "<p>just try these MATLAB API :</p>\n<p>fid = fopen('path/filename.csv') ;</p>\n<p>dcells = textscan(fid, 'your-format-string' , 'Delimiter', ',', 'Headerlines', 1 &nbsp;) ;</p>\n<p>fclose(fid) ;</p>\n<p>Them ,all data have been load in dcells .</p>\n<p>good luck ~</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 60165,
      "author_name": "anujamkelkar",
      "author_url": "",
      "post_date": "12/13/2014 23:09:30",
      "content": "<p>Thanks!&nbsp;</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 60166,
      "author_name": "toddschultz",
      "author_url": "",
      "post_date": "12/13/2014 23:27:26",
      "content": "<p>Or better yet, use the new datastore feature in R2014b. See the example code below.&nbsp;</p>\n<p>Cheers!</p>\n\n<p>%% Avazu Example Datastore Code</p>\n<p>ftrain = 'train.csv';</p>\n<p>% Create datastore object to perform partial data reads</p>\n<p>ds = datastore(ftrain);</p>\n<p>% Define data formats for each variable</p>\n<p>% variables removed from new dataset: device_os, device_make, device_geo_country</p>\n<p>ds.SelectedFormats = {'%q'... % id</p>\n<p>'%d'... % click</p>\n<p>'%d'... % hour</p>\n<p>'%C'... % C1</p>\n<p>'%C'... % banner_pos</p>\n<p>'%C'... % site_id</p>\n<p>'%C'... % site_domain</p>\n<p>'%C'... % site_category</p>\n<p>'%C'... % app_id</p>\n<p>'%C'... % app_domain</p>\n<p>'%C'... % app_category</p>\n<p>'%q'... % device_id - ignore</p>\n<p>'%q'... % device_ip - ignore</p>\n<p>'%C'... % device_model</p>\n<p>'%C'... % device_type</p>\n<p>'%C'... % device_conn_type</p>\n<p>'%C'... % C14</p>\n<p>'%C'... % C15</p>\n<p>'%C'... % C16</p>\n<p>'%C'... % C17</p>\n<p>'%C'... % C18</p>\n<p>'%C'... % C19</p>\n<p>'%C'... % C20</p>\n<p>'%C'}; % C21</p>\n\n<p>%% Read in all of the click variable</p>\n<p>ds.SelectedVariableNames = 'click';</p>\n<p>click = readall(ds);</p>\n<p>click = logical(click.click);</p>\n<p>%% Partial reads to sample</p>\n<p>% Read in first row to initialize table variable</p>\n<p>ds.RowsPerRead = 1;</p>\n<p>data = read(ds);</p>\n<p>% Reset number of rows per read</p>\n<p>ds.RowsPerRead = 20000;</p>\n<p>% Read in a block and process</p>\n<p>while hasdata(ds)</p>\n<p>tempdata = read(ds);</p>\n<p>% Pull random sample without replacement</p>\n<p>tempdata = datasample(tempdata,100,'Replace',false);</p>\n\n<p>data = [data; tempdata];</p>\n<p>end</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 60168,
      "author_name": "anujamkelkar",
      "author_url": "",
      "post_date": "12/13/2014 23:47:26",
      "content": "<p>Textscan doesnt seem to work because data doesn't fit in memory. Also, datastore isn't present in R2014a, which is the version of MATLAB I am using.</p>\n<p>Any solution to this data problem?</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "60126": "",
    "60140": "",
    "60165": "",
    "60166": "",
    "60168": ""
  },
  "source": "meta"
}