Input matrix contains NaN or Inf: how to solve it?

15 views (last 30 days)
Dear all,
I am trying to solve a model using matlab. However, I always got an error message at a specific point, stating that "Input matrix contains NaN or Inf". I checked my results and I noticed that there are some NaN or Inf values, but I do not know how to solve this problem.
The problem arises when the function gx_hx is used and regards some terms on the 22nd column of variable/matrix called "B" (look at gx_hx to understand how B is defined). In "open model" you can find all the equations of my model and you can see the 22nd equations, which probably the wrong one. In "open ss" you can find the steady state values and in "open run", you can run all the codes.
Thank you in advance for your time!

Answers (1)

KSSV
KSSV on 18 Aug 2021
Check why you are getting NaN/ inf. Mostly you will get when you 0/0, 1/0. Also if your value goes beyong the floating-point representation you are bound get Inf. You can find NaN/ inf in the data using isnan. You can fill the NaN's in the data using fillmissing.
  1 Comment
Kitty
Kitty on 9 Mar 2025
Edited: Kitty on 9 Mar 2025
This doesn't work. There are scenarios where this would work, but this answer isn't specific enough to be helpful. The documentation isn't much better. I have run a report and that shows when values are encountered that will not let the simulation complete, this is probably the best way to narrow it down since all Simulink says is very unhelpful and that the 'matrix must not contain NaN or Inf values'. So for anyone else having the issue I recommend going to 'Modeling' tab, then 'System Design Report'.

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!