Number to matrix
37 views (last 30 days)
Show older comments
student on 9 Feb 2012
Edited: Cedric Wannaz on 8 Oct 2013
I am very new to MatLab. I am wondering, what is the simplest way to convert a 5-digit number into a matrix of those 5 digits.
Walter Roberson on 9 Feb 2012
sprintf('%d', TheNumber) - '0'
is the simplest, but not the most efficient.
Benjamin Schwabe on 9 Feb 2012
You can do that by simply using the following code:
p = 12345; % define your number
It will work for all integer numbers. For non Integer numbers, the "." will be transformed into 'NaN'.
Walter Roberson on 10 Feb 2012
When you are dealing with single digits, subtracting the character '0' is much more efficient than str2double().
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!