sample_code_for_Fig1.m 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. % Load images (n=303)
  2. % Natural images: 1-300
  3. % Black: image 301
  4. % Gray: image 302
  5. % White: image 303
  6. imagedata = h5read('responses2naturalimages.h5','/images');
  7. % Load spike rasters and receptive field information
  8. spikedata = h5read('responses2naturalimages.h5','/spikes');
  9. mudata = h5read('responses2naturalimages.h5','/mu'); % Center coordinates
  10. sigmadata = h5read('responses2naturalimages.h5','/sigma'); % Sigma matrices (convariance matrices)
  11. % Prepare figure
  12. figure;
  13. set(gcf,'Position', [100 100 100+880 100+300]);
  14. % IDs for sample cell and image of Fig. 1 in manuscript
  15. CellID = 44;
  16. ImageID = 228;
  17. % Plot sample image
  18. subplot(1,2,1)
  19. thisimage = squeeze(imagedata(:,:,ImageID));
  20. imagesc(thisimage);
  21. hold on;
  22. set(gca,'YDir','normal');
  23. axis([0, 256, 0, 256] );
  24. axis equal;
  25. xlabel('Pixels')
  26. ylabel('Pixels')
  27. colormap gray;
  28. caxis([-1 1])
  29. % Plot RF outline at 3 sigma
  30. mu = mudata(:,CellID);
  31. sigma = sigmadata(:,:,CellID);
  32. i = zeros(2,1e3);
  33. for j=1:size(i,2)
  34. alpha = 2*pi*(j-1)/(size(i,2)-1);
  35. i(:,j) = 3*sqrtm(sigma)*[cos(alpha);sin(alpha)]+mu;
  36. end
  37. plot(i(1,:),i(2,:),'b','LineWidth',2);
  38. % Get spike rasters for sample cell and sample image
  39. data = squeeze(spikedata(:,:,:,CellID));
  40. Raster = squeeze(data(:,:,ImageID));
  41. % Get all the trials for this cell and image
  42. NTrial = nnz(sum(Raster,1));
  43. Raster = Raster(:,1:NTrial)';
  44. subplot(1,2,2)
  45. imagesc(Raster)
  46. set(gca,'YDir','normal');
  47. xlabel('Time [ms]')
  48. ylabel('Trial')