%% Find Number of Endmembers Using NWHFC Method
% Read hyperspectral data into the workspace.

hcube = hypercube('jasperRidge2_R198.hdr');

% Find the number of endmembers in the hyperspectral data by using the NWHFC method.

numEndmembers = countEndmembersHFC(hcube);

% Estimate the endmember spectra using the N-FINDR method.

endmembers = nfindr(hcube,numEndmembers);

% Plot the endmember spectra.

figure
plot(endmembers)
title(['Number of Endmembers: ' num2str(numEndmembers)])
xlabel('Band Number')
ylabel('Data Values')   

% Copyright 2020 The MathWorks, Inc.