function [] = matchedPCAplot(dFF, M, sttype, i1, i2, r, c, ind) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %Performs the PCA for matching neurons between 2 dFF matrics and plots the %output % Inputs: % - dFF: Cell array of the dFF matrics for a mouse % - M: the nx2 matric of matching neurons % - il: The cell corresponding to column 1 of M in dFF % - i2: the cell corresponding to column 2 of M in dFF % - r: Number of rows in the subplot matrix % - c: number of columns in the subplot matrix % - ind: the 4 indices in the subplot matrix to plot the data on. Done % this way to allow for multiple comparisons on a single figure (r and % c can result in a large matrix than the indexes in ind) % Output: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ndFF = cat(2, dFF{i1}(M(:, 1), :), dFF{i2}(M(:, 2), :)); %Concatenate the 2 relevant dFF matrices nframe = size(dFF{i1}(M(:, 1), :), 2); %Number of frames in video 1 [coeff,score,latent,tsquared,explained,mu] = pca(ndFF','Centered', 'off'); [B, I] = sort(coeff(:, 1)); %Show the matrix of concatenated neural activity subplot(r, c, ind(1)) imagesc(ndFF(I, :)) hold on xline(size(dFF{i1}(M(:, 1), :), 2)) hold off title(strcat(sttype{i1}, 32, 'vs', 32, sttype{i2})); ylabel('Cell Number') colorbar %Plot the temporal evolution of the PCs for video 1 subplot(r, c, ind(2)) x = score(1:nframe, 1)'; y = score(1:nframe, 2)'; z = score(1:nframe, 3)'; col = 1:length(x); % This is the color, vary with x in this case. surface([x;x],[y;y],[z;z],[col;col],... 'facecol','no',... 'edgecol','interp',... 'linew',2); colormap(squeeze(cat(3, linspace(0, 1, 255), zeros(1, 255), linspace(1, 0, 255)))) view([-37.5 30]) % plot(score(:, 1:min([size(coeff, 1) 3]))); % xlabel('Frame') % xlim([0 size(score, 1)]) title(sttype{i1}) xlabel('PC 1') ylabel('PC 2') zlabel('PC 3') y1 = ylim; x1 = xlim; z1 = zlim; %Plot the temporal evolution of the PCs for video 2 subplot(r, c, ind(3)) x = score((nframe+1):end, 1)'; y = score((nframe+1):end, 2)'; z = score((nframe+1):end, 3)'; col = 1:length(x); % This is the color, vary with x in this case. surface([x;x],[y;y],[z;z],[col;col],... 'facecol','no',... 'edgecol','interp',... 'linew',2); colormap(squeeze(cat(3, linspace(0, 1, 255), zeros(1, 255), linspace(1, 0, 255)))) view([-37.5 30]) title(sttype{i2}) xlabel('PC 1') ylabel('PC 2') zlabel('PC 3') y2 = ylim; x2 = xlim; z2 = zlim; yn(1) = min([y1(1) y2(1)]); yn(2) = max([y1(2) y2(2)]); xn(1) = min([x1(1) x2(1)]); xn(2) = max([x1(2) x2(2)]); zn(1) = min([z1(1) z2(1)]); zn(2) = max([z1(2) z2(2)]); subplot(r, c, ind(2)) xlim(xn) ylim(yn) zlim(zn) subplot(r, c, ind(3)) xlim(xn) ylim(yn) zlim(zn) %Plot the temporal evolution for videos 1 and 2 merged. Colormap assumes %videos 1 and 2 are the same length subplot(r, c, ind(4)) x = score(:, 1)'; y = score(:, 2)'; z = score(:, 3)'; col = 1:length(x); % This is the color, vary with x in this case. ax1 = gca; surface(ax1, [x;x],[y;y],[z;z],[col;col],... 'facecol','no',... 'edgecol','interp',... 'linew',2); cmap = squeeze(cat(3, linspace(0, 1, 127), zeros(1, 127), linspace(1, 0, 127))); cmap2 = squeeze(cat(3, linspace(1, 0, 128), linspace(0, 1, 128), linspace(0, 1, 128))); colormap(ax1, squeeze(cat(1, cmap, cmap2))) view([-37.5 30]) title(strcat(sttype{i1}, 32, 'to', 32, sttype{i2})) xlabel('PC 1') ylabel('PC 2') zlabel('PC 3')