Hi Amrutha,
When comparing PCA results between MATLAB and SPSS, there are several factors that can lead to differences in the plots, even when using the same dataset.Here's a cleaned-up version of your MATLAB code using pca, which is more modern and recommended over princomp:
% Read and preprocess data
A = xlsread('sn30.xlsx');
A = A';
[n, m] = size(A);
% Standardize the data
AMean = mean(A);
AStd = std(A);
B = (A - AMean) ./ AStd;
% Perform PCA
[coeff, score, latent, tsquare] = pca(B);
% Extract principal component scores
PC1 = score(:, 1);
PC2 = score(:, 2);
PC3 = score(:, 3);
% Plot the first three principal components
figure;
hold on;
for ii = 1:8
plot3(PC1(ii), PC2(ii), PC3(ii), 'r*');
end
for ii = 9:15
plot3(PC1(ii), PC2(ii), PC3(ii), 'bo');
end
for ii = 16:25
plot3(PC1(ii), PC2(ii), PC3(ii), 'g^');
end
xlabel('PC1');
ylabel('PC2');
zlabel('PC3');
title('PCA Plot');
grid on;
hold off;
