1 view (last 30 days)

I have a reference vector u=[0.5 1 1.5 0.6981 1.3962 1.5707].

I want to estimate this vector via an algorithm. For that I am using an Algorithm "Flower Pollination" which returns me a vector of the same size as u. This returned vector is my estimated vector. I run this algorithm 100 times and each time I get an estimated vector of the same size as u. For this iteration, I have set up a for loop like this:

for n=100:199

[out1,out2,out3]=flower(n,Remaining input arguments---)

temp(nn,:)=out1;

------------

-----------

%-------------Check for swapping-----------------

if abs((temp(nn,1)-u(2)))< abs((temp(nn,1)-u(1)))

two(nn,:)=[temp(nn,2) temp(nn,1) temp(nn,3) temp(nn,5) temp(nn,4) temp(nn,6)];

elseif abs((temp(nn,1)-u(3)))< abs((temp(nn,1)-u(1)))

two(nn,:)=[temp(nn,3) temp(nn,2) temp(nn,1) temp(nn,6) temp(nn,5) temp(nn,4)];

elseif abs((temp(nn,2)-u(3)))< abs((temp(nn,1)-u(1)))

two(nn,:)=[temp(nn,1) temp(nn,3) temp(nn,2) temp(nn,4) temp(nn,6) temp(nn,5)];

else

two(nn,:)=temp(nn,:);

end

end

The output "out1" is a vector returned by the algorithm which is not exactly equal to u but is nearly equal to u. i.e. each element of out1

is nearly equal to each element of u.But when I run this code, and check the 100 estimated vectors. In some of these vectors, positions of estimated elements have been interchanged and in some of these vectors there is no position interchange.If the change ocuurs, its like this:

Positions 1 and 2 interchange with each other

Positions 1 and 3 interchange with each other

Positions 2 and 3 interchange with each other

Then I manually re-arrrange those estimated vectors.I want that Matlab should check each of them in advance and re-arrange them automatically before displaying them.

Regards

Opportunities for recent engineering grads.

Apply Today
## 3 Comments

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/491423-how-to-arrange-a-vector-elements-on-the-pattern-of-a-reference-vector#comment_767998

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/491423-how-to-arrange-a-vector-elements-on-the-pattern-of-a-reference-vector#comment_767998

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/491423-how-to-arrange-a-vector-elements-on-the-pattern-of-a-reference-vector#comment_768007

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/491423-how-to-arrange-a-vector-elements-on-the-pattern-of-a-reference-vector#comment_768007

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/491423-how-to-arrange-a-vector-elements-on-the-pattern-of-a-reference-vector#comment_768019

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/491423-how-to-arrange-a-vector-elements-on-the-pattern-of-a-reference-vector#comment_768019

Sign in to comment.