我可以通过键盘输入单行矩阵。如
x = {};
n = 3;
For[k = 1, k ≤ n, k++,
br = Input[Row[{"Enter the ", k, " element"}]];
AppendTo[x, br];
]
这将获得单行矩阵,如x = {2,3,6}。但如果我想通过键盘输入x = {{2,3,4},{4,5,6},{0,1,0}}那么我该怎么办?
答案 0 :(得分:1)
优于For
循环:
x = Table[
Input[Row[{ "enter component:" , i , j}] ], {i, 3}, {j, 3}]
最好还是试试这个:
Table[ ToExpression@StringSplit[
InputString[
Row[{"enter row", i ,
" ( three numbers space separated)" }]]], {i, 3}]