Search code examples
matlabplotraster

MATLAB and Raster Plots


I've looked through all raster related things on stackoverflow for Matlab and have not been able to find a useful and easy way for making a raster plot of some data.

The raster plot I want to make uses the following vector:

X =[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0;]

in this vector, a 0 = no response and a 1= a response. Each element also represents 0.1s. I want to make a plot that represents the data as a raster in the following way:

| ||| | | | |||||| | | |

---> Time (note: this example does not correspond to the data I have given)

where Time is on the X-Axis and each line corresponds to a 1 (i.e. a response). Does anyone have some suggestions on how to do this?

I did use Matlab's command for a sparsity plot, but it is not quite what I am looking for. Also, I tried linalg::raster but I do not have the toolbox this command requires.


Solution

  • Based on your drawing I assume you are looking for

    stem(X,'Marker','none')
    

    And for the time axis you could do something like

    t = (1./(24.*60.*60.*10)).*(1:length(X)) ;
    stem(t,X,'Marker','none') 
    datetick