Dear all , I still need an answer

1 回表示 (過去 30 日間)
imola
imola 2014 年 8 月 7 日
編集済み: imola 2015 年 2 月 17 日
Dear Patrik thank you very much, that's really quick, but I see that the numbers have changed and the total number to every number is not 11, I'm going to be more precise, I need to have before the point four positions for example
[0011741667, 0003913892,0014488700,0008746350,0000349066] so the final string should be
00117416670003913892001448870000087463500000349066
while we got 1174173913914488787463034907 and I tried to change the { } to [] but it gave me error, in the end I have matrix [20,5] to convert in the same way , could you help me to overcome this problem. thanks
I will write my question again.
Dear all, I'm going to write my problem again, I need to convert the vector [11.741667 3.913892 14.488700 8.746350 0.349066] to integer numbers
[11741667 3913892 14488700 8746350 0349066] without the point, then join them to be string like 00117416670003913892001448870000087463500000349066
thanks in advance, I really appreciate your help.
  2 件のコメント
Geoff Hayes
Geoff Hayes 2014 年 8 月 7 日
Imola - are you using your own genetic algorithm code to optimize a problem, or are you using that from the (MATLAB) Global Optimization Toolbox. I think I understand what you are doing (please correct me if I'm wrong) - you have five floating point variables that you wish to concatenate into a single string of integer values. This will be the "genetic" data from one parent which you will crossover with that from another parent, creating the child genetic data. This combined string will then be broken down back into the five variables (genes?) which will be used to evaluate the child's fitness via the fitness function.
Is this correct? Are you using just one crossover point or multiple? Why not use a heuristic approach on each gene/variable which allows you to maintain the floating point data?
Geoff Hayes
Geoff Hayes 2014 年 8 月 7 日
Imola - the heuristic approach just takes the two equivalent genes/variables from the two parents and creates the child gene according to the equation
childVarX = parent2VarX + R * (parent1VarX - parent2VarX);
where parent1 has the better fitness value, and R determines how far the child variable value should be from the better parent. Just Google GA "heuristic crossover" and a couple of papers should appear.
Also see MATLAB GA Crossover Options and look at the heuristic section.

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

採用された回答

Evan
Evan 2014 年 8 月 7 日
編集済み: Evan 2014 年 8 月 7 日
Is this what you mean?
x = [0011741667,0003913892,0014488700,0008746350,0000349066];
s = regexprep(sprintf('%011.6f', x),'[.\s]','');

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGenetic Algorithm についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by