This question is closed. Reopen it to edit or answer.

elements order is not same in estimated vector as in my desired vector

1 view (last 30 days)
I have an m file that is as follows:
half_1st = 1:3; %half_1st = 1:3;
half_2nd = 4:6; %half_2nd = 4:6;
for n=1:100 %------------(2)
%--Call FPA
[best,fmin,N_iter,time]=fpa(10,0.8,10000,dim,[0 0 0 0 0 0],[10 10 10 pi pi pi])%-------------(A)
temp(nn,:)=best; % Best estimated vector
time1(nn)=time; %Elapsed_Time;
%----Check the estimated vector placed in temp for Swapping
[sortTemp, sortIndex] = sort(temp(nn,half_1st));
two(nn,:)= temp(nn,[half_1st(sortIndex) half_2nd(sortIndex)]);
%%%%%%%%%%%%%%%%%%%%%%%% End of code%%%%%%%%%%%%%%%%%%%%%%
In this I call Flower Pollination algorithm (fpa) which returns me 4 variables. There is a vector u inside fpa already defined by me
u=[3 1 5 105*th 155*th 50*th];
The fpa algorithm generates its own vectors of same size as above u. Then it sends those vectors to my fitness function and fitness is checked of those vectors
there. The vector whose fitness has minimum value is returned by fpa as "best" vector. And that vector is actually the same as my u. In other words that fpa algorithm
estimates my desired vector. But the problem is that when the fpa algorithm generates its owns vectors, the order of inside elements of each of them is changing.So the
position of the elements in estimated vector may not be the same as in my u vector. For that someone had helped me here to have the same order in the setimated vector as
that of my vector u. That help was as:
[sortTemp, sortIndex] = sort(temp(nn,half_1st));
two(nn,:)= temp(nn,[half_1st(sortIndex) half_2nd(sortIndex)]);
But when I run the program, it returns the estimated vector as:
estimated vector=[1 3 5 2.7053 1.8326 0.87266].
i.e. as you can see the positions of the elements of u and estimated vector are not the same. I want to get the same order of the elemements in the estimated vector as in u.
[SL: Formatted the text part of the question as text not code]

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by