NaNs from str2double on Arduino hardware
Afficher commentaires plus anciens
I'm running a Simulink model with a Matlab Function Block on an Arduino Mega 2560. The Matlab code includes converting a string to a double.
E.g.:
function x = convert(str)
x = str2double(str);
It works in Normal mode simulation, but when running on the hardware (External mode) I keep getting NaNs returned in x instead of the number. To try to work out what's wrong, I've tried the following simplified code:
x = str2double('32'); % returns NaN
x = str2double('32.0') % returns 32
Can anyone explain this behaviour, and what do I do to get over it? I've tried using real() function and that seems to make no difference.
2 commentaires
Stephen23
le 14 Oct 2019
Start by checking:
- that the correct function is being called (e.g. which str2double -all).
- the actual input data does not contain any non-numeric characters (convert to double and print in the command window. Show us some examples).
Richard Stephens
le 14 Oct 2019
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Arduino Hardware dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!