This still shows up in search results, so I wanted to add the datasample function as an option. The following code will provide a weighted sample of 5 units from fromVector according the corresponding vector myWeights.
mySample = datasample(fromVector, 5, 'Replace', false, 'Weights', myWeights)