How can I write the code of the matrix calculations ?

1 次查看(过去 30 天)
I need some help to write the code of the calculations below. Let out matrix be like the one below.
[X11 X12... X1n [1 3 5
X21 X22... X2n 2 4 1
Xm1 Xm2... Xmn] 4 6 2]
I added the objection function values of each row in their row.(onj. function is the sum of elements in each row.)
[X11 X12... X1n ObV1 [ 1 3 5 9
X21 X22... X2n ObV2 2 4 1 7
Xm1 Xm2... Xmn ObVm] 4 6 2 12]
I want to give ranks to the rows according to their objective function values in an ascending order and sort them.
[2 4 1 7 1
1 3 5 9 2
4 6 2 12 3]
Then I want to choose the first two one as best ones and the rest is worst. Like select the first two rows and create new rows from them according to this function
NewOne(m,n)=BestOne(m,n)+(rand()/coefficient)*BestOne(m,n)
For example;
NewOne= [2 4 1]+ (0.4/2)*[2 4 1]=[2.4 4.8 1.2]
Thanks in advance.
  1 个评论
CarenCaren
CarenCaren 2016-5-12
编辑:CarenCaren 2016-5-12
Initial Matrix [X11 X12... X1n [1 3 5
X21 X22... X2n 2 4 1
Xm1 Xm2... Xmn] 4 6 2]
Objec. func. values [X11 X12... X1n ObV1 [1 3 5 9
X21 X22... X2n ObV2 2 4 1 7
Xm1 Xm2... Xmn ObVm] 4 6 2 12]
Ranked [2 4 1 7 1
1 3 5 9 2
4 6 2 12 3]
NewOne(m,n)=BestOne(m,n)+(rand()/coefficient)*BestOne(m,n)
For example; NewOne= [2 4 1]+ (0.4/2)*[2 4 1]=[2.4 4.8 1.2]

请先登录,再进行评论。

采纳的回答

Andrei Bobrov
Andrei Bobrov 2016-5-12
X = [1 3 5
2 4 1
4 6 2];
[~,ii] = sort(sum(X,2));
B = X(ii,:);
NewOne = B + bsxfun(@times,rand(size(X,1),1)./B(:,1),B);
  1 个评论
CarenCaren
CarenCaren 2016-5-12
Like select the first two rows and create new rows from them according to this function.
NewOne(m,n)=BestOne(m,n)+(rand()/coefficient)*BestOne(m,n)
For example;
NewOne= [2 4 1]+ (0.4/2)*[2 4 1]=[2.4 4.8 1.2]
and the new row created from the row with the worst obj. function value according to
New One= WorstOne+rand()*WorstOne. How can I separate the rows and apply this equations for creating new rows from them? For example I want to select the first n rows and apply them equation 1, and for the rest ı want to apply equation 2.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by