User Tools

Site Tools


analysis:course-w16:week3long

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
analysis:course-w16:week3long [2016/01/17 17:54]
mvdm [PlotTSDFromIV]
analysis:course-w16:week3long [2018/07/07 10:19] (current)
Line 1: Line 1:
 ~~DISCUSSION~~ ~~DISCUSSION~~
  
-:!: UNDER CONSTRUCTION -- DO NOT USE YET! +===== Module 3: Visualizing neural data in MATLAB =====
- +
-===== Module 3: Visualizing neural data in MATLAB ​(long version) ​=====+
  
 Goals: Goals:
Line 9: Line 7:
   * Master the basics of plotting data in MATLAB using the versatile ''​plot()''​ function   * Master the basics of plotting data in MATLAB using the versatile ''​plot()''​ function
   * Understand how to use //handles// to fine-tune formatting   * Understand how to use //handles// to fine-tune formatting
-  * Meet some existing visualization tools: ''​MultiRaster()'',​ ''​PlotTSDfromIV()''​ and ''​ft_dataviewer()''​ +  * Meet some existing visualization tools: ''​MultiRaster()'',​ ''​PlotTSDfromIV()''​ and ''​ft_databrowser()''​ 
-  * Use interactive figure properties for dynamic data viewing+  * Use interactive figure properties ​with callback functions ​for dynamic data viewing
   * Learn to use functions with variable numbers of input arguments (using ''​varargin''​ and ''​cfg''​ inputs) effectively   * Learn to use functions with variable numbers of input arguments (using ''​varargin''​ and ''​cfg''​ inputs) effectively
   * Understand which file format to export figures to   * Understand which file format to export figures to
Line 17: Line 15:
 Resources: Resources:
  
-  * (reference) MATLAB documentation for ''​plot'',​ [[ http://​www.mathworks.com/​help/​matlab/​ref/​figure_props.html | Figure properties ]], [[ http://​www.mathworks.com/​help/​matlab/​ref/​axes_props.html | Axis properties ]] and [[ http://​www.mathworks.com/​help/​matlab/​ref/​line_props.html | Line Properties ]]+  * (reference) MATLAB documentation for ''​plot'',​ [[ http://​www.mathworks.com/​help/​matlab/​ref/​figure_props.html | Figure properties]],​ [[ http://​www.mathworks.com/​help/​matlab/​ref/​axes_props.html | Axis properties]] and [[ http://​www.mathworks.com/​help/​matlab/​ref/​line_props.html | Line Properties]]
   * (reference) [[http://​www.mathworks.com/​help/​matlab/​creating_plots/​figures-plots-and-graphs.html | MATLAB plotting gallery ]]   * (reference) [[http://​www.mathworks.com/​help/​matlab/​creating_plots/​figures-plots-and-graphs.html | MATLAB plotting gallery ]]
   * (reference) [[http://​www.vandermeerlab.org/​BIOL377_assignment3_2012.pdf | Place cell assignment]] from %%MvdM%%'​s BIOL377 course at Waterloo from a few years ago (if you want a gentle intro to what is going on in the data you are looking at; can be done in 30 min)   * (reference) [[http://​www.vandermeerlab.org/​BIOL377_assignment3_2012.pdf | Place cell assignment]] from %%MvdM%%'​s BIOL377 course at Waterloo from a few years ago (if you want a gentle intro to what is going on in the data you are looking at; can be done in 30 min)
Line 152: Line 150:
 </​code>​ </​code>​
  
-This way, you have precise control over the formatting of command line output -- the cryptic ''​%5.3f''​ tag specifies that the contents of ''​this_spk''​ should be formatted as a floating-point number with digits before, and 3 digits following, the decimal point; ''​\n''​ specifies a newline. (For reference: ''​fprintf()''​ has [[http://​www.mathworks.com/​help/​matlab/​ref/​fprintf.html#​input_argument_formatspec | many other formatting options]]).+This way, you have precise control over the formatting of command line output -- the cryptic ''​%4.3f''​ tag specifies that the contents of ''​this_spk''​ should be formatted as a floating-point number with digits before, and 3 digits following, the decimal point; ''​\n''​ specifies a newline. (For reference: ''​fprintf()''​ has [[http://​www.mathworks.com/​help/​matlab/​ref/​fprintf.html#​input_argument_formatspec | many other formatting options]]).
  
 Now that we know what we are dealing with, let's meet the plot() command: Now that we know what we are dealing with, let's meet the plot() command:
Line 309: Line 307:
 The topics that follow in this section are optional, in the sense that later modules do not assume you know how to do these things. Feel free to use this section as you see fit, but do make sure you go through the next section ("​Using existing visualization tools"​)! The topics that follow in this section are optional, in the sense that later modules do not assume you know how to do these things. Feel free to use this section as you see fit, but do make sure you go through the next section ("​Using existing visualization tools"​)!
  
-==== Interactive figures ====+==== Interactive figures ​and callback functions ​====
  
 Figure windows in MATLAB have many properties (here is the complete [[http://​www.mathworks.com/​help/​matlab/​ref/​figure-properties.html | list]]). A particularly useful one is the ''​KeyPressFcn''​ property, which specifies a function to be called when a key is pressed while the figure is active. Figure windows in MATLAB have many properties (here is the complete [[http://​www.mathworks.com/​help/​matlab/​ref/​figure-properties.html | list]]). A particularly useful one is the ''​KeyPressFcn''​ property, which specifies a function to be called when a key is pressed while the figure is active.
Line 465: Line 463:
 </​code>​ </​code>​
  
-If you can't get this to work, the resulting file is here; Windows Media Player synthesizes it with a plain piano instrument, which is effective at communicating the sudden, violently synchronous activity during SWRs!+If you can't get this to work, the resulting file can be made to sound like this {{:​analysis:​course-w16:​r042.mp3|here}} (with Ableton Live); Windows Media Player synthesizes it with a plain piano instrument, which sounds a bit different but is also effective at communicating the sudden, violently synchronous activity during SWRs!
 ===== Using existing visualization tools ===== ===== Using existing visualization tools =====
  
Line 482: Line 480:
 % %
 cfg_plot = []; cfg_plot = [];
-cfg_plot.lfp(1) = csc;+cfg_plot.lfp = csc;
 cfg_plot.spkColor = '​jet';​ cfg_plot.spkColor = '​jet';​
-cfg_plot.evt(1) = metadata.taskvars.trial_iv_L;​ % "​left"​ trials on the T-maze+cfg_plot.evt = metadata.taskvars.trial_iv_L;​ % "​left"​ trials on the T-maze
  
 h = MultiRaster(cfg_plot,​S);​ h = MultiRaster(cfg_plot,​S);​
 </​code>​ </​code>​
 +
 +You should get:
 +
 +{{ :​analysis:​course-w16:​plot_tutorial6.png?​nolink&​600 |}}
  
 Now, press the '​h'​ key to bring up a window explaining the various keyboard shortcuts available. These work through the ''​KeyPressFcn''​ method introduced above; you can examine MultiRaster'​s ''​KeyPressFcn''​ by typing ''​edit navigate''​ (it's called ''​navigate.m''​). Now, press the '​h'​ key to bring up a window explaining the various keyboard shortcuts available. These work through the ''​KeyPressFcn''​ method introduced above; you can examine MultiRaster'​s ''​KeyPressFcn''​ by typing ''​edit navigate''​ (it's called ''​navigate.m''​).
Line 558: Line 560:
  
 ☛ Try the other display mode, '''​tsd'''​. ☛ Try the other display mode, '''​tsd'''​.
-==== ft_dataviewer ​====+==== FieldTrip'​s databrowser ​==== 
 + 
 +As implied by the name, ''​MultiRaster()''​ is primarily intended for plotting spike data, although it can accept multiple tsd's for plotting as well.  
 + 
 +The %%FieldTrip%% toolbox, which will be covered in more detail in later modules, has a number of data visualization tools that are better suited for plotting time series data such as LFPs, EEG/MEG and single-trial fMRI data.  
 + 
 +To get our current data into the %%FieldTrip%% format, we first have to do a few steps: 
 + 
 +<code matlab>​ 
 +% convert to ft format 
 +cfg = []; cfg.mode = '​resample';​ 
 +csc_ft = TSDtoFT(cfg,​csc);​ 
 +t0 = csc_ft.time{1}(1);​ csc_ft.time{1} = csc_ft.time{1}-t0;​ 
 + 
 +% create ft trials from iv 
 +trl_cfg = []; 
 +trl_cfg.t = IVcenters(metadata.SWRtimes)-t0;​ 
 +trl_cfg.mode = '​neuralynx';​ 
 +trl_cfg.hdr = csc_ft.hdr;​ 
 +trl_cfg.twin = [-1 1]; 
 + 
 +trl = ft_maketrl(trl_cfg);​ 
 + 
 +% use trials to create trialified data structure 
 +temp_cfg = []; temp_cfg.trl = trl; 
 + 
 +ft_in = ft_redefinetrial(temp_cfg,​csc_ft);​ 
 +</​code>​  
 + 
 +Now we can run the data browser by typing ''​ft_databrowser([],​ft_in);'',​ to get 
 + 
 +{{ :​analysis:​course-w16:​plot_tutorial8.png?​nolink&​600 |}}
  
 +Notice the various control buttons for moving between trials, channels (here we have only one loaded), and other functions, documented [[http://​www.fieldtriptoolbox.org/​faq/​how_can_i_use_the_databrowser | here]]. %%FieldTrip%% is able to load many types of data files, see [[http://​www.fieldtriptoolbox.org/​reading_data | here]] for the list and how to use its data loaders.
 ===== Challenges ====== ===== Challenges ======
  
analysis/course-w16/week3long.1453071285.txt.gz · Last modified: 2018/07/07 10:19 (external edit)