Skip to content

Commit 1f7c31e

Browse files
Fixed some typos, added some infos in the function main section and added the code to handle the (required) presence of the Text Analytics Toolbox.
1 parent c7f7c7b commit 1f7c31e

File tree

1 file changed

+81
-14
lines changed

1 file changed

+81
-14
lines changed

toolbox/graphics/pcaProjection.m

Lines changed: 81 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ function pcaProjection(Y,varargin)
77
% details of the orthogonal projection of trivariate points onto the space of the
88
% first 3 principal components and displays the principal ellipsoid in both
99
% the original and projected spaces.
10+
% More precisely 6 distinct plots are created:
11+
% 1. A 3D scatterplot with the line associated with the 1st PC.
12+
% 2. A 3D scatterplot with main line and orthogonal projections.
13+
% 3. A 3D scatterplot with orthogonal projections onto first 2 PCs plane
14+
% of first 2 PC.
15+
% 4. A 3D scatterplot projections onto the first three PCs.
16+
% 5. A 3D scatterplot with the principal ellipsoid in the original coordinates space.
17+
% 6. A 3D scatterplot with the principal ellipsoid in the projected coordinates space.
18+
1019
%
1120
% Required input arguments:
1221
%
@@ -67,8 +76,8 @@ function pcaProjection(Y,varargin)
6776
% Example - 'standardize',false
6877
% Data Types - boolean
6978
%
70-
%TextDensityPercentage: Percentage of text data to show.
71-
% Scalar from 0through 100. Percentage of text data
79+
%TextDensityPercentage: Percentage of text data to show.
80+
% Scalar from 0 through 100. Percentage of text data
7281
% to show, specified as a scalar from 0 through 100.
7382
% To show all text, set TextDensityPercentage to
7483
% 100. To show no text, set TextDensityPercentage to
@@ -153,7 +162,7 @@ function pcaProjection(Y,varargin)
153162
%{
154163
%% Call to pcaProjection with option standardize.
155164
load citiesItaly.mat
156-
% This is the effect of non standardized the data when
165+
% This is the effect of non standardizing the data when
157166
% standardization is needed!
158167
pcaProjection(citiesItaly(:,[ 1 2 5]),'standardize',false)
159168
%}
@@ -279,7 +288,13 @@ function pcaProjection(Y,varargin)
279288
axis equal
280289
title("3D scatter plot with the line associated with first PC")
281290

282-
textscatter3(Xtilde(:,1),Xtilde(:,2),Xtilde(:,3),rownames,'TextDensityPercentage',TextDensityPercentage)
291+
info = ver('textanalytics');
292+
if isempty(info)
293+
fprintf('Text Analytics Toolbox is NOT installed.\n Units labels will not be shown.');
294+
else
295+
textscatter3(Xtilde(:,1),Xtilde(:,2),Xtilde(:,3),rownames,'TextDensityPercentage',TextDensityPercentage)
296+
end
297+
283298
xlabel(varnames(1))
284299

285300

@@ -302,7 +317,15 @@ function pcaProjection(Y,varargin)
302317

303318
title("3D scatter plot with main line and orthogonal projections")
304319

305-
textscatter3(Xtilde(:,1),Xtilde(:,2),Xtilde(:,3),rownames,'TextDensityPercentage',TextDensityPercentage)
320+
321+
info = ver('textanalytics');
322+
if isempty(info)
323+
fprintf('Text Analytics Toolbox is NOT installed.\n Units labels will not be shown.');
324+
else
325+
textscatter3(Xtilde(:,1),Xtilde(:,2),Xtilde(:,3),rownames,'TextDensityPercentage',TextDensityPercentage)
326+
end
327+
328+
306329
xlabel(varnames(1))
307330
ylabel(varnames(2))
308331
zlabel(varnames(3))
@@ -330,8 +353,17 @@ function pcaProjection(Y,varargin)
330353
constantplane(V(:,3),0)
331354
end
332355

333-
textscatter3(Xtilde(:,1),Xtilde(:,2),Xtilde(:,3),rownames, ...
334-
'TextDensityPercentage',TextDensityPercentage);
356+
357+
358+
info = ver('textanalytics');
359+
if isempty(info)
360+
fprintf('Text Analytics Toolbox is NOT installed.\n Units labels will not be shown.');
361+
else
362+
textscatter3(Xtilde(:,1),Xtilde(:,2),Xtilde(:,3),rownames, ...
363+
'TextDensityPercentage',TextDensityPercentage);
364+
end
365+
366+
335367
xlabel(varnames(1))
336368
ylabel(varnames(2))
337369
zlabel(varnames(3))
@@ -346,8 +378,17 @@ function pcaProjection(Y,varargin)
346378

347379
title('3D scatter plot of projections onto the first three principal components');
348380

349-
textscatter3(Xtilde*v1,Xtilde*v2,Xtilde*v3,rownames,'TextDensityPercentage',TextDensityPercentage);
350-
xlabel('PC1'); ylabel('PC2'); zlabel('PC3');
381+
382+
383+
info = ver('textanalytics');
384+
if isempty(info)
385+
fprintf('Text Analytics Toolbox is NOT installed.\n Units labels will not be shown.');
386+
else
387+
textscatter3(Xtilde*v1,Xtilde*v2,Xtilde*v3,rownames,'TextDensityPercentage',TextDensityPercentage);
388+
xlabel('PC1'); ylabel('PC2'); zlabel('PC3');
389+
end
390+
391+
351392

352393
color='k';
353394

@@ -357,7 +398,7 @@ function pcaProjection(Y,varargin)
357398
end
358399
end
359400

360-
%% Ellpsoid in the space of the PCs
401+
%% Ellipsoid in the space of the PCs
361402
figure
362403
scatter3(Xtilde*v1,Xtilde*v2,Xtilde*v3)
363404

@@ -369,7 +410,16 @@ function pcaProjection(Y,varargin)
369410
[xr,yr,zr]=ellipsoid(0,0,0,facProp*Gam(1),facProp*Gam(2),facProp*Gam(3));
370411

371412
surf(xr,yr,zr,'FaceColor','none')
372-
textscatter3(Xtilde*v1,Xtilde*v2,Xtilde*v3,rownames,'TextDensityPercentage',TextDensityPercentage);
413+
414+
415+
416+
info = ver('textanalytics');
417+
if isempty(info)
418+
fprintf('Text Analytics Toolbox is NOT installed.\n Units labels will not be shown.');
419+
else
420+
textscatter3(Xtilde*v1,Xtilde*v2,Xtilde*v3,rownames,'TextDensityPercentage',TextDensityPercentage);
421+
end
422+
373423

374424

375425
for j=1:3
@@ -393,7 +443,15 @@ function pcaProjection(Y,varargin)
393443
XX1=XX*V';
394444
nfac=sqrt(size(XX1,1));
395445
surf(reshape(XX1(:,1),nfac,nfac),reshape(XX1(:,2),nfac,nfac),reshape(XX1(:,3),nfac,nfac),'FaceAlpha',0.1,'FaceColor','none');
396-
textscatter3(Xtilde(:,1),Xtilde(:,2),Xtilde(:,3),rownames,'TextDensityPercentage',TextDensityPercentage);
446+
447+
info = ver('textanalytics');
448+
if isempty(info)
449+
fprintf('Text Analytics Toolbox is NOT installed.\n Units labels will not be shown.');
450+
else
451+
textscatter3(Xtilde(:,1),Xtilde(:,2),Xtilde(:,3),rownames,'TextDensityPercentage',TextDensityPercentage);
452+
end
453+
454+
397455

398456
for j=1:3
399457
if AddAxes(j) == true
@@ -418,8 +476,17 @@ function addLinePCj(V,Xtilde,j,lwd)
418476
% Add the line associated with jth PC
419477
line([Xhatj(indminXj,1); Xhatj(indmaxXj,1)], [Xhatj(indminXj,2); Xhatj(indmaxXj,2)], ...
420478
[Xhatj(indminXj,3); Xhatj(indmaxXj,3)],'LineWidth',lwd);
421-
textscatter3(Xhatj(indmaxXj,1), Xhatj(indmaxXj,2), ...
422-
Xhatj(indmaxXj,3),"PC"+j);
479+
480+
481+
info = ver('textanalytics');
482+
if isempty(info)
483+
fprintf('Text Analytics Toolbox is NOT installed.\n Units labels will not be shown.');
484+
else
485+
textscatter3(Xhatj(indmaxXj,1), Xhatj(indmaxXj,2), ...
486+
Xhatj(indmaxXj,3),"PC"+j);
487+
end
488+
489+
423490
end
424491

425492
function add3Daxes(j,color,lwd)

0 commit comments

Comments
 (0)