jeudi 31 octobre 2019

Random sampling of elements from an array based on a target condition

I have an array (let's call it 'ElmInfo') of size N x 2 representing a geometry. In that array the element number and element volume are on the column 1 and column 2 respectively. The volume of elements largely vary. The sum of the volume of all elements leads to a value 'V' which can be obtained in Matlab as: V=sum(ElmInfo(:,2));

I want to randomly sample elements from the array 'ElmInfo' in such a way that the volume of sampled elements (with no repetition) will lead to a target volume 'V1'. Note: V1 is less than V. So I don't know the number of elements to be sampled. I am giving an example. For a sampling case number of sampled element can be '10' whereas in other sampling number of sampled element can be '15'.

There is no straightforward Matlab in-built function to meet the target condition. How can I implement the code in Matlab?




Aucun commentaire:

Enregistrer un commentaire