我是 matlab 新手。如果 e
的值为 NaN
,我想返回 0。以下是我的代码:
if(e!='NaN')
fprintf(1,'The final coefficiant is: %f \n',e);
else
return 0;
end
它向我展示了
Unexpected MATLAB operator.
谁能告诉我为什么?应该怎么写呢?
最佳答案
此外 != 也不是有效的 MATLAB 运算符。那是你的错误。
使用 ~=
没有什么是永远、永远、永远 == NaN。
连 NaN 都没有。使用isnan
function out = my_fun(e)
if ~isnan(e)
fprintf('The final coefficiant is: %f \n',e);
out = 1; % or whatever
else
out = 0;
end
关于matlab中无法返回零值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19795693/