程序报错下标索引必须为正整数类型或逻辑类型。

% 更新接收器收到的光强
r_idx = floor(sqrt(x^2 + y^2) / dr) + 1;
z_idx = floor(z / dz) + 1;
if r_idx <= length(r_bins) && z_idx <= length(z_bins)
received_power(z_idx, r_idx) = received_power(z_idx, r_idx) + I;
end
报错信息:下标索引必须为正整数类型或逻辑类型
出错 jg (line 37)
received_power(z_idx, r_idx) = received_power(z_idx, r_idx) + I;
求助这是什么情况

 Réponse acceptée

firqang
firqang le 14 Mai 2023

0 votes

try里面要放出错语句,否则catch是抓不到的。
建议按照下面示例写:
部分代码示例.....
try
received_power(z_idx, r_idx) = received_power(z_idx, r_idx) + I;
catch
z_idx
r_idx
end
这样的话,在函数报出上面错误的时候,就会进入catch分支,然后就会把z_idx, r_idx打印到命令窗口。
你就能知道出错时候,这两个值是什么了。

Plus de réponses (0)

Catégories

En savoir plus sur 图形对象的标识 dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!