I am running the following code, which works most of the time but occasionally causes issues. The problem is that ocassionally the values in 'topfit' will have more than 1 match in the matrix 'totalsale', so the 'position' variable is not a constant size. Due to the nature of the rest of the code it is imperative position be just 10 figures.
I have tried just limiting position to 10 figures manually by setting position = position(1:10,:) but that has it's own problems.
position = find(ismember(totalsale,topfit));
topstack = finalpop(position,:);
finalpop is a 100x16 matrix.
Totalsale is a 100x1 matrix of the fitness values of the rows in finalpop.
Topfit is a 10x1 matrix, the top 10 totalsale fitness values, in descending order.
Can anyone recommend a way to return only the 10 rows in finalpop which produced the top 10 fitness values? Could I assign each a number 1-10 and somehow assign that to finalpop to find them? Stuck for ideas. Thanks!
If the fitness values produced were : 100,99,98,97,96,95,94,93,92,91,91,91,91
I would like to return the finalpop values that produced the first 10 and ignore the other three 91 values, even though they are just as fit.