If word1 = 'A', what is str2num? What is int16?

1 view (last 30 days)
Jacob Holcombe
Jacob Holcombe on 22 Feb 2017
Commented: John D'Errico on 22 Feb 2017
I am just a little confused about this. The str2num would return nothing, correct? And as for the int16 part, I am completely clueless. Any help is greatly appreciated. Thanks.
  1 Comment
John D'Errico
John D'Errico on 22 Feb 2017
What int16 part? The crystal ball is so cloudy, that we simply cannot see into your mind or your computer.
help int16
As far as str2num('A') goes, yes, it would produce an empty result, since there is no number present. While you can feel free to interpret 'A' as a hex number, str2num cannot know that to be true.
After all, if str2num were to do that, then would you really expect it to return a numeric representation for strings of words that just happen to also be valid hex numbers? 'DAD', 'ADD', 'DEAD', etc.
Finally, I've seen it recommended that str2double is a better/safer choice than str2num. This is because str2num uses an eval internally, so if that string included a function call, nasty things can happen if the user has devious intentions.

Sign in to comment.

Answers (0)

Tags

Products

Community Treasure Hunt

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

Start Hunting!