Syslab 中使用 exp 函数出现报错:ERROR: MethodError: objects of type Matrix{Int64} are not callable
技术分享
发布于 2025-07-22 14:46:20
查看 2过去315天
问题现象
Syslab 中使用 exp 函数出现报错:ERROR: MethodError: objects of type Matrix{Int64} are not callable
代码如下:
M = 6;
d = 0.7;
theta = -5.4
phase = 1*[375 365 70 60 125 115]
array = exp(complex.(2*(phase(1:6))/360));
解决方法
上述代码中存在两个问题需要修改:
1.问题一:引用数组向量需要使用方括号而不是圆括号,因此需要将上述代码修改为:
M = 6;
d = 0.7;
theta = -5.4
phase = 1*[375 365 70 60 125 115]
#array = exp(complex.(2*(phase(1:6))/360));
array = exp(complex.(2*(phase[1:6])/360)); #将圆括号改为方括号
2.运行步骤1中的代码仍然出现报错,根据报错信息提示 exp 函数处理的数据为向量

3.问题二:处理数据为向量时需要在 exp 函数后面加上“.”,因此需要将上述代码修改为:
M = 6;
d = 0.7;
theta = -5.4
phase = 1*[375 365 70 60 125 115]
#array = exp(complex.(2*(phase(1:6))/360));
#array = exp(complex.(2*(phase[1:6])/360));
array = exp.(complex.(2*(phase[1:6])/360)); #将圆括号改为方括号;在exp 后加上 .
4.运行代码后在命令行中输入 array 并回车,可以看到得到了正确的结果:

所属专栏:Syslab基础平台
产品信息:Syslab科学计算环境