1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
| clear all
close all
clc
filename= input('Quel est le nom du fichier à ouvrir?','s')
fprintf ('votre base de donnée est:\n')
plumat=xlsread(filename)
[A,B] = size(plumat);
[NUMERIC,TEXTE]=xlsread(filename);
% Données centrées et réduites
fprintf ('La moyenne vaut:\n')
moyenne= mean(plumat);
moyenne
fprintf ('l ecart type vaut:\n')
ectyp= std(plumat,1);
ectyp
for i=1:A
for j=1:B
plumatCR(i,j)=(plumat(i,j)-moyenne(j))/ectyp(j);
end
end
plumatCR
%Cormat
cormat=corrcoef(plumatCR);
[vecp valp]=eig(cormat);
%Test conditions ACP
inertie=valp/trace(valp);
if((inertie(1,1)+inertie(2,2))<0.8)
reply=input('!!! ATTENTION,Conditions ACP non vérifiées!!!Voulez vous quand même poursuivre?(oui/non)?','s');
if(reply=='non')
fprintf('Fin du programme\n');
end
end
if((inertie(1,1)+inertie(2,2))<0.8&reply=='oui'|(inertie(1,1)+inertie(2,2))>0.8)
end
%Calcul de la base
u1=vecp(:,1);
u2=vecp(:,2);
%extraction des données
ville=TEXTE(3:end,1);
mois=TEXTE(1,2:end);
%Coordonnées pour le premier graphe
X=plumatCR*u1;
Y=plumatCR*u2;
X
Y
%Graphe 1
figure(1)
plot (X,Y,'o')
title('Distance entre les individus')
datacursormode on
plot(X,Y,'o');
hold on
str = num2str((1:numel(X)).','%1d');
text(X+0.01,Y+0.01,str)
%for i=1:A
legend(ville(:,1))
%end
%Coordonnées(2)
for i=1:B
temp1= corrcoef(plumatCR(:,i),X);
xmois(i)=temp1(1,2);
temp2= corrcoef(plumatCR(:,i),Y);
ymois(i)=temp2(1,2);
end
%Graphe2
figure(2)
compass(xmois,ymois)
title('COORDONNEES DES VARIABLES')
datacursormode on |
Partager