Obslabel error when using biplot

12 ビュー (過去 30 日間)
desert_scientist90
desert_scientist90 2020 年 2 月 5 日
コメント済み: desert_scientist90 2020 年 2 月 11 日
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

採用された回答

Payas Bahade
Payas Bahade 2020 年 2 月 11 日
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 件のコメント
desert_scientist90
desert_scientist90 2020 年 2 月 11 日
Thanks for your help, a simple detail indeed but was driving me crazy.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with Statistics and Machine Learning Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by