错误:输入矩阵不能包含 NaN 或 Inf 值。

15 visualizaciones (últimos 30 días)
龙
el 10 de Mzo. de 2025
Respondida: cdarling el 4 de Jun. de 2025
错误:输入矩阵不能包含 NaN 或 Inf 值。

Respuestas (1)

cdarling
cdarling el 4 de Jun. de 2025
你好,这个报错与具体情况有关,MATLAB是支持NaN或Inf的值的,也支持这些值作为矩阵的元素输入到函数中,比如
>> sum([1 NaN Inf])
ans =
NaN
如果要生成类似报错,可以在代码中使用throw或者error,比如:
>> if any(isnan([1 NaN Inf]))
error('输入矩阵不能包含 NaN 或 Inf 值')
end
输入矩阵不能包含 NaN Inf

Categorías

Más información sobre NaNs en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!