【问题标题】:Single point crossover单点交叉
【发布时间】:2017-06-06 08:11:46
【问题描述】:

我有两个数组(一行矩阵)temp1temp2 如下:

temp1=[1 2 3 4 5 6 7 8 9]
temp2=[10 11 12 13 14 15 16 17 18]

我有一个索引pn=3。我需要如下输出:

tempNew=[1 2 3 13 14 15 16 17 18]

即如何创建 tempNew 以使索引上的所有值直到 pn 都来自 temp1 而索引之外的所有值 pn 都来自 temp2

【问题讨论】:

  • [temp1(1:pn),temp2(pn:end)] ?

标签: matlab crossover


【解决方案1】:
temp1=[1 2 3 4 5 6 7 8 9]
temp2=[10 11 12 13 14 15 16 17 18]
pn=3;
tempNew = [temp1(1:pn),temp2(pn+1:end)]
tempNew =
     1     2     3    13    14    15    16    17    18

您使用pn 创建两个临时数组来索引您的两个tempX 数组。然后只需使用方括号将它们连接起来。

在 MATLAB 中,索引始终从 1 开始,因此 1:pn 将为您提供数组的第一个 pn 值。 end 表示数组的结尾,因此pn+1:end 将为您提供从索引pn+1 到数组最后一个的所有值。

【讨论】:

    猜你喜欢
    • 2013-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-10
    • 2013-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多