Obslabel error when using biplot

12 visualizzazioni (ultimi 30 giorni)
Hi I have a biplot with the PCA results from 9 houses and 14 variables. I am trying to label my scores with the correspondent chemical name. I am using the following code but matlab is giving me this error message. I already tried to transpose my cells and no luck. Any guidance will be appreciated.
Thanks
Z = zscore(spw); % Standardized data
[coefs,score,v,g,ex] = pca(Z);
vbls = {'1','2','3','4','5','6','7','8', '9'}; % Array of variable labels for houses
Pah={'Naph','2Methyl','1Methyl','Acy','Ace','Flu','Phe','Ant','Flt','Pyr','BaAnt', 'Chr', 'BbFlu','BkFLu','BePyr'};% chem names
h6 = biplot(coefs(:,1:2),'Scores',score(:,1:2),'ObsLabels',Pah, 'VarLabels', vbls);
Error using biplot (line 219)
'ObsLabels' value must be a character array, string array. or cell array of character vectors with one label
for each row of the 'Scores' matrix.
september.jpg

Risposta accettata

Payas Bahade
Payas Bahade il 11 Feb 2020
Hi,
There seems to be a mismatch between number of Observation Labels (chemical names) and number of rows in ‘score’ matrix. Number of Observation Labels must be same as number of rows in ‘score’ matrix. In question it is mentioned that number of variables is 14, but ‘Pah’ has 15 labels. To avoid the mismatch please check the size of ‘score’ matrix and provide equal number of labels in ‘Pah’ variable.
Also, I created a sample ‘spw’ variable of size 15x9 with random numbers and tested in the code as provided by you. It seems to work fine.
spw = randn(15,9);%Random numbers
Z = zscore(spw); % Standardized data
[coefs,score,v,g,ex] = pca(Z);
vbls = {'1','2','3','4','5','6','7','8', '9'}; % Array of variable labels for houses
Pah={'Naph','2Methyl','1Methyl','Acy','Ace','Flu','Phe','Ant','Flt','Pyr','BaAnt', 'Chr', 'BbFlu','BkFLu','BePyr'};% chem names
h6 = biplot(coefs(:,1:2),'Scores',score(:,1:2),'ObsLabels',Pah, 'VarLabels', vbls);
Biplot.JPG
Hope this helps!
  1 Commento
desert_scientist90
desert_scientist90 il 11 Feb 2020
Thanks for your help, a simple detail indeed but was driving me crazy.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Get Started with Statistics and Machine Learning Toolbox in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by