# I have multiple vectors of order (1000*24)have calculated the fitness of all these.Now the want the maximum out of fitness and want the corresponding vectors and index of that

1 ビュー (過去 30 日間)
Muhammad 2022 年 10 月 15 日

AA
0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0
0 1 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0
0 0 0 0 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 1 0
0 0 0 1 0 0 0 1 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0
0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1
0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 0
0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0
0 0 0 0 1 0 0 0 0 0 1 0 0 0 1 0 1 0 0 0 0 0 0 0
0 0 0 0 0 1 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 1 0 0
fitness=1/1+cost
Cost is calculated from price
p=[ 1 4 2 3 5 6 7 8 9 4 11 12 13 14 2 3 4 5 2 4 5 6 7 8]
I want to sort the fitness and want the maximum out of that values and also the corresponding vector and its index,related to max fitness value.
##### 2 件のコメント表示 1 件の古いコメント非表示 1 件の古いコメント
Muhammad 2022 年 10 月 17 日
let Clansize_11=size(AA)
for i=1:Clansize_11
if AA(i)<=Clansize_11
Energy(i,:)=(Pr_kw).*(AA(i,:));
Cost(i,:)= (Energy(i,:)).*p;
Summation=sum(Cost,2);
BB=[Summation];
end
end
fitnessx = [];
for i=1:Clansize_11
fitnessx(i)= 1/(1+Summation(i))
Now evaluate fitness sort it and then min the min and max of fitness and also find the vector coressponding to that max or min of fitness.

サインインしてコメントする。

### 回答 (1 件)

dpb 2022 年 10 月 17 日
>> Clansize_11=size(AA)
>> Clansize =
10 24
>>
will return a 2-vector of the number rows/columns of AA. What then do you think is the purpose of
for i=1:Clansize_11
if AA(i)<=Clansize_11
...
will just operate over
>> for i=1:Clansize_11,disp([i AA(i) AA(i)<=Clansize_11]),end
1 0 1 1
2 0 1 1
3 0 1 1
4 0 1 1
5 0 1 1
6 0 1 1
7 0 1 1
8 0 1 1
9 0 1 1
10 0 1 1
>>
the first column of the array, (shown by the first column above is "i", but given that AA contains nothing but 0/1, the test is going to be true for every element in the array, even though only the first column will be tested.
On top of which, the logical test will also return a 2-vector the size of the 2-vector Clansize_11 of the test against [10 24] of either a 0 or 1 (since the first column is all 0, it's just 0 <=[10 24] which as the last two columns shows, is going to be one everywhere.
If it is intended that AA is a logical variable of when to compute the E variable, then use the MATLAB array operations and the times, .* "dot" operators; there's no need for a loop.
Energy=Pr_kw.*AA;
Cost=Price_kw*Energy;
TotalCost=sum(Cost,2);
Fitness=1./(1+TotalCost);
At this point it shouldn't be hard to find the other statistics you've outlined...

サインインしてコメントする。

### カテゴリ

Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by