-1

我收到以下错误

ERROR: "Cannot `convert` an object of type Array{Float64,2} to an object of type #Array{Float64,13} This may have arisen from a call to the constructor #Array{Float64,13}(...), since type constructors 

这是我尝试过的代码:

type buscase
baseMVA::Float64
bus::Array{Float64,13}
gen::Array{Float64,21}
branch::Array{Float64,13}
end

mpc=buscase(100.00,
[1  2   0   0   0   0   1   1   0   230 1   1.1 0.9;
2   1   300 98.61   0   0   1   1   0   230 1   1.1 0.9;
3   2   300 98.61   0   0   1   1   0   230 1   1.1 0.9;
4   3   400 131.47  0   0   1   1   0   230 1   1.1 0.9;
5   2   0   0   0   0   1   1   0   230 1   1.1 0.9;],

[1  40  0   30  -30 1   100 1   40  0   0   0   0   0   0   0   0   0   0   0   0;
1   170 0   127.5   -127.5  1   100 1   170 0   0   0   0   0   0   0   0   0   0   0   0;
3   323.49  0   390 -390    1   100 1   520 0   0   0   0   0   0   0   0   0   0   0   0;
4   0   0   150 -150    1   100 1   200 0   0   0   0   0   0   0   0   0   0   0   0;
5   466.51  0   450 -450    1   100 1   600 0   0   0   0   0   0   0   0   0   0   0   0;],

[1  2   0.00281 0.0281  0.00712 400 400 400 0   0   1   -360    360;
1   4   0.00304 0.0304  0.00658 0   0   0   0   0   1   -360    360;
1   5   0.00064 0.0064  0.03126 0   0   0   0   0   1   -360    360;
2   3   0.00108 0.0108  0.01852 0   0   0   0   0   1   -360    360;
3   4   0.00297 0.0297  0.00674 0   0   0   0   0   1   -360    360;
4   5   0.00297 0.0297  0.00674 240 240 240 0   0   1   -360    360;]
)
4

1 回答 1

1

这就是你应该如何定义你的结构

struct buscase
   baseMVA::Float64
   bus::Array{Float64,2}
   gen::Array{Float64,2}
   branch::Array{Float64,2}
end

现在您的命令mpc=buscase(100.00, ....将起作用

就像前面所说的,Array定义中的数字表示参数的数量。

您还可以使用Matrix较短形式的类型Array{T,2}

struct buscase
   baseMVA::Float64
   bus::Matrix{Float64}
   gen::Matrix{Float64}
   branch::Matrix{Float64}
end

最后但并非最不重要的一点是,如果您想为数组设置固定大小,您应该查看StaticArrays.jlpackage.json 。但是,对于最多 10-20 个元素的数组(取决于观察到的性能增益),建议使用此包。

于 2018-09-06T13:58:46.083 回答