# NaN values with correlation metrics

I am using the Peak to Correlation Energy (PCE) Metric to measure the similarity between two images using MATLAB. In some cases, the PCE value obtained is NaN. How can I solve this problem?

• Either your input data is broken, or your algorithm is. The solution is to fix your input data, or your algorithm! So the first step is to validate your input data: is there any infinities, NaNs in there? If so, you'll have to decide what you want your metric to be in that case. Feb 20 '21 at 19:02
• No problem with input data, and no problem with the algorithm, it works well with other examples
– Noha
Feb 20 '21 at 19:33
• Clearly, either one of your statements is false, or both. Your algorithm clearly produces undersired output, so start investigating. We can't read your data or your algorithm's implementation from here, that's up to you. Feb 20 '21 at 19:42
• Try dbstop if naninf. That should stop execution when a NaN or inf gets created and you can expect your code and data right when the problem happens. And yes, it's either your data or your algorithm or possible the combination of both. Feb 20 '21 at 20:01
• A NaN (Not a Number) exception happens when a 0/0, or Inf / Inf, or inf - inf is encountered. Check your data for these extreme cases. Note that any value less than a threshold, say 1E-325 for matlab, may be treated as 0 too. Feb 20 '21 at 20:35