Hi Mira,
Since you already have your structure field “weights” sorted, you can make use of “unique” function here. MATLAB function “unique” returns unique values in array, along with the rank as well.
The following command should return the rank of the weights as you expect.
>> [~,~,rank] = unique(R.Weights)
You can also refer to this documentation page for further reference.
https://www.mathworks.com/help/matlab/ref/double.unique.html