%% Specify Parameters to Compute Endmembers
% Read a hyperspectral data into the workspace.

hcube = hypercube('paviaU.hdr');

% Find the number of spectrally distinct endmembers present in the hyperspectral data cube by using countEndmembersHFC function.

numEndmembers = countEndmembersHFC(hcube,'PFA',10^-7);

% Compute the endmembers using the pixel purity index (PPI) method. Specify the number of unit vectors to be used for projection as 100. Also, select principal component analysis (PCA) method for dimensionality reduction.

endmembers = ppi(hcube.DataCube,numEndmembers,'NumVectors',100,'ReductionMethod','PCA');

% Plot the endmembers of the hyperspectral data.

figure
plot(endmembers)
xlabel('Band Number')
ylabel('Pixel Values')
ylim([0 9000])
title({'Endmembers Spectra',['Number of Endmembers = ' num2str(numEndmembers)]});

% Copyright 2020 The MathWorks, Inc.