How to group and convert to decimal?
Afficher commentaires plus anciens
The output of r is 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 1
I want to group every 8 digits and convert to decimal
Please help
4 commentaires
Please show what you have done so far.
doc bin2dec
doc reshape
Image Analyst
le 4 Fév 2013
Is the output of your r() function a string, or a numerical array (such as double or int32 or logical)? If it's a string, are there spaces between the digits?
Sharen H
le 4 Fév 2013
Image Analyst
le 4 Fév 2013
Modifié(e) : Image Analyst
le 4 Fév 2013
You mean an "array" of doubles is returned by r(), like this [0, 0, 0, 1, 0, 1, 0, etc.], not just a single double like you implied. So, it's like what Azzi assumed.
Réponse acceptée
Plus de réponses (1)
Converting from a double vector to a string and back to a double inside bin2dec is not efficient. Better convert from binary to decimal values directly:
x = [ 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 1];
d = 2 .^ (length(x)-1:-1:0) * x(:);
Catégories
En savoir plus sur Data Type Conversion 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!