简单讲就是,你以为 n / 0.0005 是一系列整数,但这只是你以为。实际上由于浮点存储精度,很多计算结果是 整数 ± 1e-12 这样的非整数。
这种情形应当避免使用 向量 / 步长 去算索引,而应改以索引为循环变量,由索引去算向量元素。比如改为
for Index = 1 : 1 : numel( n ) % 索引为正整数
Current_n = n( Index );
% 其他计算同理
end
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!