I have run this script several times successfully, but I made a few changes to the folders where I was storing files and variables, and now I am getting this error message:
Unrecognized function or variable 'pcaBinnedSpikes'.
Error in M28_PoS_PCA (line 27)
[coeff, score, latent, tsquared, explained, mu] = pca(pcaBinnedSpikes');
Here is the code:
% State Space Visualization and PCA
% Pre-Process Data
headangledeg = rad2deg(headangle); % convert from radians to degrees
startTime = trackingtimes(1);stopTime = trackingtimes(end);% Make a matrix of activity for all neurons that 'spiked' at least 1000 times during the session. The shape of the matrix should be N by T, where N is the number of neurons and T is the number of time bins. Use the binning from the tracked head direction. Smooth the activity of each neuron with a Gaussian with ? = 10 time bins and then standardize the activity: (activity-mean(activity))/standard deviation(activity).
j=1; for c=1:length(M28_PoS_spikes) if ~idx(c) continue end spikes = M28_PoS_spikes{c}; spikes = spikes(spikes > startTime & spikes < stopTime); if length(spikes) >= 1000 edgesT = linspace(startTime,stopTime,numel(trackingtimes)+1); binnedSpikes = histcounts(spikes,edgesT); binnedSpikes = smoothdata(binnedSpikes,2,'gaussian',50); pcaBinnedSpikes(j,:) = zscore(binnedSpikes); j = j+1; endend% Run PCA
% Reduce the dimensionality of the matrix from N by T to 2 using Principal Component Analysis (PCA)
[coeff, score, latent, tsquared, explained, mu] = pca(pcaBinnedSpikes');% Visualize the Population Activity
% Make a plot of the time points of the experiment, color-coded according to tracked head direction angle
figurecolormap hsvscatter(score(:,1),score(:,2),15,headangle,'.')axis equalxlabel('1st Principal Component')ylabel('2nd Principal Component')title('Mouse 28 PoS PCA - High MI','FontSize',12)
I do define pcaBinnedSpikes, so I am not sure why I get the error message now.
Best Answer