我是Mathematica的新手,我正在尝试创建一个输入函数,该函数将返回遗传算法的后代列表,但代码返回
Null Return[{}]
在询问后代的数量之后。如何让代码运行并返回输入的后代列表?谢谢!
inputData[]:= (
i = 1
offspring = {};
offspringSize = Input["Enter number of offspring"];
While[i <= offspringSize,
n = Input[
"Enter data in form {Potential 1, Potential 2, Number of cycles, \
Cycle Length, Wave Form, Result}"];
offspring = Append[offspring, n];
n =.;
i++;
];
Print[offspring]
Return[offspring]
);
newData = inputData[]
答案 0 :(得分:0)
让我们简化一下。然后显示进入两个后代的结果。
In[1]:= inputData[] := (offspringSize = Input["Enter number of offspring"];
offspring = Table[Input[
"Enter data in form {Potential 1, Potential 2, Number of
cycles, Cycle Length, Wave Form, Result}"], {offspringSize}];
Print[offspring];
offspring);
newData = inputData[]
During evaluation of In[1]:= {{1,3,5,7,9,11},{2,4,6,8,10,12}}
Out[2]= {{1, 3, 5, 7, 9, 11}, {2, 4, 6, 8, 10, 12}}