plx_ts.html 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2. "http://www.w3.org/TR/REC-html40/loose.dtd">
  3. <html>
  4. <head>
  5. <title>Description of plx_ts</title>
  6. <meta name="keywords" content="plx_ts">
  7. <meta name="description" content="plx_ts(filename, channel, unit): Read spike timestamps from a .plx file">
  8. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  9. <meta name="generator" content="m2html &copy; 2005 Guillaume Flandin">
  10. <meta name="robots" content="index, follow">
  11. <link type="text/css" rel="stylesheet" href="../../../m2html.css">
  12. <script type="text/javascript">
  13. if (top.frames.length == 0) { top.location = "../../../index.html"; };
  14. </script>
  15. </head>
  16. <body>
  17. <a name="_top"></a>
  18. <!-- ../../menu.html chronux_2_10 --><!-- ../menu.html dataio --><!-- menu.html ReadingPLXandDDTfilesinMatlab -->
  19. <h1>plx_ts
  20. </h1>
  21. <h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../../up.png"></a></h2>
  22. <div class="box"><strong>plx_ts(filename, channel, unit): Read spike timestamps from a .plx file</strong></div>
  23. <h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../../up.png"></a></h2>
  24. <div class="box"><strong>function [n, ts] = plx_ts(filename, ch, u) </strong></div>
  25. <h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../../up.png"></a></h2>
  26. <div class="fragment"><pre class="comment"> plx_ts(filename, channel, unit): Read spike timestamps from a .plx file
  27. [n, ts] = plx_ts(filename, channel, unit)
  28. INPUT:
  29. filename - if empty string, will use File Open dialog
  30. channel - 1-based channel number
  31. unit - unit number (0- invalid, 1-4 valid)
  32. OUTPUT:
  33. n - number of timestamps
  34. ts - array of timestamps (in seconds)</pre></div>
  35. <!-- crossreference -->
  36. <h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../../up.png"></a></h2>
  37. This function calls:
  38. <ul style="list-style-image:url(../../../matlabicon.gif)">
  39. </ul>
  40. This function is called by:
  41. <ul style="list-style-image:url(../../../matlabicon.gif)">
  42. </ul>
  43. <!-- crossreference -->
  44. <h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../../up.png"></a></h2>
  45. <div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function [n, ts] = plx_ts(filename, ch, u)</a>
  46. 0002 <span class="comment">% plx_ts(filename, channel, unit): Read spike timestamps from a .plx file</span>
  47. 0003 <span class="comment">%</span>
  48. 0004 <span class="comment">% [n, ts] = plx_ts(filename, channel, unit)</span>
  49. 0005 <span class="comment">%</span>
  50. 0006 <span class="comment">% INPUT:</span>
  51. 0007 <span class="comment">% filename - if empty string, will use File Open dialog</span>
  52. 0008 <span class="comment">% channel - 1-based channel number</span>
  53. 0009 <span class="comment">% unit - unit number (0- invalid, 1-4 valid)</span>
  54. 0010 <span class="comment">% OUTPUT:</span>
  55. 0011 <span class="comment">% n - number of timestamps</span>
  56. 0012 <span class="comment">% ts - array of timestamps (in seconds)</span>
  57. 0013
  58. 0014 <span class="keyword">if</span>(nargin ~= 3)
  59. 0015 disp(<span class="string">'3 input arguments are required'</span>)
  60. 0016 <span class="keyword">return</span>
  61. 0017 <span class="keyword">end</span>
  62. 0018
  63. 0019 n = 0;
  64. 0020 ts = 0;
  65. 0021 <span class="keyword">if</span>(isempty(filename))
  66. 0022 [fname, pathname] = uigetfile(<span class="string">'*.plx'</span>, <span class="string">'Select a plx file'</span>);
  67. 0023 filename = strcat(pathname, fname);
  68. 0024 <span class="keyword">end</span>
  69. 0025
  70. 0026 fid = fopen(filename, <span class="string">'r'</span>);
  71. 0027 <span class="keyword">if</span>(fid == -1)
  72. 0028 disp(<span class="string">'cannot open file'</span>);
  73. 0029 <span class="keyword">return</span>
  74. 0030 <span class="keyword">end</span>
  75. 0031
  76. 0032 disp(strcat(<span class="string">'file = '</span>, filename));
  77. 0033
  78. 0034 <span class="comment">% read file header</span>
  79. 0035 header = fread(fid, 64, <span class="string">'int32'</span>);
  80. 0036 freq = header(35); <span class="comment">% frequency</span>
  81. 0037 ndsp = header(36); <span class="comment">% number of dsp channels</span>
  82. 0038 nevents = header(37); <span class="comment">% number of external events</span>
  83. 0039 nslow = header(38); <span class="comment">% number of slow channels</span>
  84. 0040 npw = header(39); <span class="comment">% number of points in wave</span>
  85. 0041 npr = header(40); <span class="comment">% number of points before threshold</span>
  86. 0042 tscounts = fread(fid, [5, 130], <span class="string">'int32'</span>);
  87. 0043 wfcounts = fread(fid, [5, 130], <span class="string">'int32'</span>);
  88. 0044 evcounts = fread(fid, [1, 512], <span class="string">'int32'</span>);
  89. 0045
  90. 0046 <span class="comment">% skip variable headers</span>
  91. 0047 fseek(fid, 1020*ndsp + 296*nevents + 296*nslow, <span class="string">'cof'</span>);
  92. 0048
  93. 0049 <span class="comment">% read the data</span>
  94. 0050 record = 0;
  95. 0051 <span class="keyword">while</span> feof(fid) == 0
  96. 0052 type = fread(fid, 1, <span class="string">'int16'</span>);
  97. 0053 upperbyte = fread(fid, 1, <span class="string">'int16'</span>);
  98. 0054 timestamp = fread(fid, 1, <span class="string">'int32'</span>);
  99. 0055 channel = fread(fid, 1, <span class="string">'int16'</span>);
  100. 0056 unit = fread(fid, 1, <span class="string">'int16'</span>);
  101. 0057 nwf = fread(fid, 1, <span class="string">'int16'</span>);
  102. 0058 nwords = fread(fid, 1, <span class="string">'int16'</span>);
  103. 0059 toread = nwords;
  104. 0060 <span class="keyword">if</span> toread &gt; 0
  105. 0061 wf = fread(fid, toread, <span class="string">'int16'</span>);
  106. 0062 <span class="keyword">end</span>
  107. 0063 <span class="keyword">if</span> type == 1
  108. 0064 <span class="keyword">if</span> channel == ch
  109. 0065 <span class="keyword">if</span> unit == u
  110. 0066 n = n + 1;
  111. 0067 ts(n) = timestamp/freq;
  112. 0068 <span class="keyword">end</span>
  113. 0069 <span class="keyword">end</span>
  114. 0070 <span class="keyword">end</span>
  115. 0071
  116. 0072 record = record + 1;
  117. 0073 <span class="keyword">if</span> feof(fid) == 1
  118. 0074 <span class="keyword">break</span>
  119. 0075 <span class="keyword">end</span>
  120. 0076
  121. 0077 <span class="keyword">end</span>
  122. 0078 disp(strcat(<span class="string">'number of timestamps = '</span>, num2str(n)));
  123. 0079
  124. 0080 fclose(fid);</pre></div>
  125. <hr><address>Generated on Fri 12-Aug-2011 11:36:15 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" target="_parent">m2html</a></strong> &copy; 2005</address>
  126. </body>
  127. </html>