首页 > 解决方案 > How to find the frist occurrence of Nan value in a matlab code (m file)?

问题描述

I have a Matlab code (m-file) that contains many matrices and vectors. I'm doing some calculations and iterative solution. Of course some matrices depend on others, however, doing iterative calculation making it difficult for me to identify which which matrix has the first occurrence of a Nan value.

Is there any command or debugger that I can include at the top of my code to till me when exactly the first NaN value is generated?

(by when I mean at which step). or something that can stop my code once the first value of NaN is generated and probably help to find the related matrix/vector.

I have been searching the internet for possible solutions, however, all what I found, if I have know matrix, then I can find the index of the first NaN, but this is not my question. Related issues here and here, aside from many on Mathwork.

标签: matlabiterationnan

解决方案


我喜欢使用条件断点。右键单击编辑器中要停止调试的行,然后选择“设置条件断点...”

设置条件断点

弹出一个窗口,您可以在其中键入 MATLAB 代码,该代码返回一个布尔标量

配置窗口

例如,您可以测试any变量中的 if 元素x isnan


推荐阅读