Obslabel error when using biplot
13 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
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);
Hope this helps!
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File 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!