MATLAB: How to find the indices of the Self Organizing Map (SOM) training set output

Deep Learning Toolbox

When I create a SOM using the following: 
 
>> x = simplecluster_dataset;
>> net = selforgmap([10 10]);
>> net = train(net, x);
I click "SOM Sample Hits", the number in each hexagon shows how many data points are associated with each neuron. How can I know which samples in the input data (e.g. "x" in above example code) corresponding to the samples in each hexagon (neuron), or for the samples associated with a given hexagon (neuron), how can I know which samples they correspond to in the input data? 

Best Answer

It may be easier for me to explain how to do the opposite first. That is, given each input, you can see which neuron the input is classified by. You can do so by doing the following:
>> x = simplecluster_dataset;
>> net = selforgmap([10 10]);
>> net = train(net, x);
>> % click on "SOM Sample Hits"
>> input_neuron_mapping = vec2ind(net(x))';
At this point, 'input_neuron_mapping' will be a vector such that each input's value is which neuron the input has been classified by. So, if 'input_neuron_mapping(4)' was 1, this would mean that the 4th input was classified by the first neuron, which, in the plot with the hexagons, is the bottom left hexagon. The second neuron would be the one to the right of the first, and so on.
The order of the hexagon numbers will start from the bottom left and work its way up to the top right, going by rows first. 
So, if you now wanted to find which inputs a given neuron corresponded to, you could simply get the indices of 'input_neuron_mapping' equal to that neuron's number. 
For example, if you wanted to see all of the inputs that neuron 7 classified:
 
>> neuron_7_input_indices = find(input_neuron_mapping == 7)
And if you wanted to find the values of those inputs:
>> neuron_7_input_values = x(neuron_7_input_indices)