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

조회 수: 13 (최근 30일)
龙
2025년 3월 10일
답변: cdarling 2025년 6월 4일
错误:输入矩阵不能包含 NaN 或 Inf 值。

답변 (1개)

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

카테고리

Help CenterFile Exchange에서 NaNs에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!