Obslabel error when using biplot

조회 수: 13 (최근 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 CenterFile Exchange에서 Get 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