[maxweight, maxidx] = max(weights);
would give 3. That is, the largest weight is in offset 7 of weights, and in offset 7 of your ranks matrix you have stored 3.
To phrase this a different way: the weights are returned in the same order as the columns, and ranks tells you which order is the most important. You will probably find that
[~, sortorder] = sort(weights);
that sortorder and ranks is the same.
When I look at the code, I see that this is not exactly the case. The code checks to see if all of the values in a column are essentially the same, and if so then it rejects the column. The rejected columns will be listed in the ranks output after all of the accepted columns, in numeric column order.