{
  "id": 10677,
  "title": "Using the .mat files",
  "url": "/competitions/seizure-prediction/discussion/10677",
  "author_name": "",
  "post_date": "2014-10-22T05:46:05.460Z",
  "votes": null,
  "comment_count": 3,
  "views": 1387,
  "content": "<p>Hi everybody, I was able to open the mat files given in the previous competition on this topic using the R package&nbsp;&quot;R.matlab&quot;. Now even trying to open a single file results in an error</p>\n<p><code style=\"padding-left: 30px\">library(&quot;R.matlab&quot;)</code></p>\n<p><code style=\"padding-left: 30px\"></code><code style=\"padding-left: 30px\">p1 &lt;-readMat(&quot;Patient_1/Patient_1_preictal_segment_0001.mat&quot;)</code><code style=\"padding-left: 30px\">R(1050,0xac126a28) malloc: *** mmap(size=1440002048) failed (error code=12)<br>*** error: can't allocate region<br>*** set a breakpoint in malloc_error_break to debug<br>R(1050,0xac126a28) malloc: *** mmap(size=1440002048) failed (error code=12)<br>*** error: can't allocate region<br>*** set a breakpoint in malloc_error_break to debug<br>Error: cannot allocate vector of size 1.3 Gb<br>Execution halted</code></p>\n<p>I am using R version 2 15.1 and have 4 Gb of RAM. The file is 172 Mb, but I guess it expands a lot when turned into an R object. I was thinking maybe I should use some package like bigmemory or ff? Anybody had any luck with that?</p>\n<p>No luck&nbsp;trying to convert the file to csv from within Matlab:</p>\n<p><code>csvwrite('prova.csv', interictal_segment_1)<br>Undefined function 'real' for input arguments of type 'struct'.</code><code>Error in dlmwrite (line 195)<br> str = sprintf('%.*g%+.*gi',precn,real(m(i,j)),precn,imag(m(i,j)));</code><code>Error in csvwrite (line 43)<br>dlmwrite(filename, m, ',', r, c);</code></p>\n\n<p>Thank you for any suggestion!</p>",
  "messages": [
    {
      "id": "56437",
      "postDate": "10/22/2014 05:46:05",
      "content": "<p>Hi everybody, I was able to open the mat files given in the previous competition on this topic using the R package&nbsp;&quot;R.matlab&quot;. Now even trying to open a single file results in an error</p>\n<p><code style=\"padding-left: 30px\">library(&quot;R.matlab&quot;)</code></p>\n<p><code style=\"padding-left: 30px\"></code><code style=\"padding-left: 30px\">p1 &lt;-readMat(&quot;Patient_1/Patient_1_preictal_segment_0001.mat&quot;)</code><code style=\"padding-left: 30px\">R(1050,0xac126a28) malloc: *** mmap(size=1440002048) failed (error code=12)<br>*** error: can't allocate region<br>*** set a breakpoint in malloc_error_break to debug<br>R(1050,0xac126a28) malloc: *** mmap(size=1440002048) failed (error code=12)<br>*** error: can't allocate region<br>*** set a breakpoint in malloc_error_break to debug<br>Error: cannot allocate vector of size 1.3 Gb<br>Execution halted</code></p>\n<p>I am using R version 2 15.1 and have 4 Gb of RAM. The file is 172 Mb, but I guess it expands a lot when turned into an R object. I was thinking maybe I should use some package like bigmemory or ff? Anybody had any luck with that?</p>\n<p>No luck&nbsp;trying to convert the file to csv from within Matlab:</p>\n<p><code>csvwrite('prova.csv', interictal_segment_1)<br>Undefined function 'real' for input arguments of type 'struct'.</code><code>Error in dlmwrite (line 195)<br> str = sprintf('%.*g%+.*gi',precn,real(m(i,j)),precn,imag(m(i,j)));</code><code>Error in csvwrite (line 43)<br>dlmwrite(filename, m, ',', r, c);</code></p>\n\n<p>Thank you for any suggestion!</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "56438",
      "postDate": "10/22/2014 06:04:54",
      "content": "<p>csvwrite('prova.csv', interictal_segment_1.data) does work.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "56439",
      "postDate": "10/22/2014 06:08:32",
      "content": "<p>Hard to say what to tell you. I use R too, but to get it into ff, you still need to load it into memory first. Are you on a 32bit or 64bit system? That can drastically reduce your ability to create large data sets too. Otherwise, it is just a big data set and you may need to invest in more ram (surprisingly cheap these days).&nbsp; The last data sets were 1 sec long iirc (with patients up to 5khz frequency). These are 10min so (10*60)x as long.</p>\n\n<p>Of course you could ask a friend to load it for you and send it to you as csv, which you could parse into smaller chunks on your own too, but still with 15 rows and 3M columns you still might run into trouble.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "57135",
      "postDate": "10/31/2014 21:15:07",
      "content": "<p>@mario&nbsp;</p>\n<p>Here's a matlab script for converting a batch of files to csv. You can store sampling_frequency and data_length_sec data separately for each subject&nbsp;inside variables in your program.</p>\n<p>for i = 1:195<br>&nbsp; &nbsp; file = sprintf('Patient_1_test_segment_%04d.mat', i);<br>&nbsp; &nbsp; load(file);<br>&nbsp; &nbsp; str = eval(sprintf('test_segment_%d.data', i));<br>&nbsp; &nbsp; csv = sprintf('Patient_1_test_segment_%04d.csv', i);<br>&nbsp; &nbsp; dlmwrite(csv, str,'delimiter',',');<br>&nbsp; &nbsp; clear;<br>end</p>",
      "rawMarkdown": "",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 56438,
      "author_name": "mariopasquato",
      "author_url": "",
      "post_date": "10/22/2014 06:04:54",
      "content": "<p>csvwrite('prova.csv', interictal_segment_1.data) does work.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 56439,
      "author_name": "piinformatics",
      "author_url": "",
      "post_date": "10/22/2014 06:08:32",
      "content": "<p>Hard to say what to tell you. I use R too, but to get it into ff, you still need to load it into memory first. Are you on a 32bit or 64bit system? That can drastically reduce your ability to create large data sets too. Otherwise, it is just a big data set and you may need to invest in more ram (surprisingly cheap these days).&nbsp; The last data sets were 1 sec long iirc (with patients up to 5khz frequency). These are 10min so (10*60)x as long.</p>\n\n<p>Of course you could ask a friend to load it for you and send it to you as csv, which you could parse into smaller chunks on your own too, but still with 15 rows and 3M columns you still might run into trouble.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 57135,
      "author_name": "adamsoffer",
      "author_url": "",
      "post_date": "10/31/2014 21:15:07",
      "content": "<p>@mario&nbsp;</p>\n<p>Here's a matlab script for converting a batch of files to csv. You can store sampling_frequency and data_length_sec data separately for each subject&nbsp;inside variables in your program.</p>\n<p>for i = 1:195<br>&nbsp; &nbsp; file = sprintf('Patient_1_test_segment_%04d.mat', i);<br>&nbsp; &nbsp; load(file);<br>&nbsp; &nbsp; str = eval(sprintf('test_segment_%d.data', i));<br>&nbsp; &nbsp; csv = sprintf('Patient_1_test_segment_%04d.csv', i);<br>&nbsp; &nbsp; dlmwrite(csv, str,'delimiter',',');<br>&nbsp; &nbsp; clear;<br>end</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "56437": "",
    "56438": "",
    "56439": "",
    "57135": ""
  },
  "source": "meta"
}