How to write a matlab program to arrange my workspace data?
3 views (last 30 days)
I have a desired vector u=[0.5 1 2 40 70 90]. I give this vector to a metaheuristic algorithm and I run the algorithm. The algorithm runs 100 times and the algorithm does the following for me:
1-Estimates 100 such vectors for me and sotres then in variable Position, but the elements inside the estimated vectors are not in the same order as in the given vector u.
2- Estimates 100 values of fitness and stores them in variable Cost.
3- Estimates 100 velocities of the same size as u and sotres them in variable Velocity
And all above variables are stored in struct BestSol. I want to write a matlab program such that all these estimated vectors in point1 bove are sotred in the same order as u. All values in point2 above are in descending order and all values in point3 above are also in same order as u. Can any body helep me in this regard?
Thiago Henrique Gomes Lobato on 16 Feb 2020
You could use the function sort to sort your arrays and get the index of the sorting, so you can apply this indexing to u and give the index in point 3, for example. A little example to show the functionality:
Positions = [0.5 2 40 1 70 90]
[SortedPositions,Index] = sort(Positions);
0.5000 1.0000 2.0000 40.0000 70.0000 90.0000
1 4 2 3 5 6