MATLAB Answers

How can I get un-descend index of latent in pca function

1 view (last 30 days)
WonJun Choi
WonJun Choi on 9 Jun 2021
Commented: WonJun Choi on 10 Jun 2021
Hi, I'm trying to practice Neuron Spike Sorting using pca and kmeans clustering.
When I plot latent from pca function, I only get latent values which is desecended.
I want to use only 3 of them that has most powerful influence..
However, I can't find the dimension index of the big three.
My final result of spikes sorting is queit not good. I put k=2 in kmenas, but when I plot those two group, it looks same.
I guess I have a mistake finding big three powerful dimension in raw data.
Please,
spikes has 80000x48 double.
Here is my code :
%Spike Sorting
load('spikes.mat'); %detected spikes
[coeff,score,latent,tsquared,explained,mu] = pca(spikes); %PCA analysis
nscore1 = normalize(score(:,1));
nscore2 = normalize(score(:,2)); %score data normalize
nscore(:,1) = nscore1;
nscore(:,2) = nscore2;
[idx,C] = kmeans(nscore,2); %idx is clustering index
Sidx = [spikes, idx];
for k=1:size(idx)
if(Sidx(k,2)==1)
figure(1)
title('cluster1 spikes')
plot(spikes(k,:))
hold on
end
end
for k=1:size(idx)
if(Sidx(k,2)==2)
figure(2)
title('cluster2 spikes')
plot(spikes(k,:))
hold on
end
end
load('spikes.mat'); %detected spikes
[coeff,score,latent,tsquared,explained,mu] = pca(spikes); %PCA analysis
nscore1 = normalize(score(:,1));
nscore2 = normalize(score(:,2));
nscore3 = normalize(score(:,47));
figure(1)
scatter(nscore1, nscore2);
title('Normalize score1 vs Normalize score2')
xlabel('Normalize score1')
ylabel('Normalize score2')
figure(2)
scatter(nscore1, nscore3);
title('Normalize score1 vs Normalize score3')
xlabel('Normalize score1')
ylabel('Normalize score3')
figure(3)
scatter(nscore2, nscore3)
title('Normalize score2 vs Normalize score3')
xlabel('Normalize score2')
ylabel('Normalize score3')
figure(4)
scatter3(nscore1, nscore2, nscore3)
title('Normalize score1,2,3')
xlabel('Normalize score1')
ylabel('Normalize score2')
zlabel('Normalize score3')
figure(5)
plot(latent, 'o')
title('principal component') %eigen plotting

Accepted Answer

the cyclist
the cyclist on 9 Jun 2021
My answer to this question gives a detailed explanation of how to use MATLAB's pca function, including how to reduce the number of dimensions. Please read the question, my answer, the other users' comments, and my responses to those. I think it will help you.
  3 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!