How NOT remove zeros from binary number?
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello,
i've a problem: when i have read binary data from device and when i have store this data in differents variables, MATLAB removed automaticly the first zero from every variable if this one starts with zero. If not starts with zero, all it's ok. I think that MATLAB made this for spare memory...
How could i made for matlab preserve this first zero of each variables?
For example:
Device gives me: 110101 and MATLAB stores 110101
but... if Device gives me: 010101 Matlab stores 10101
Remove the first zero.
Could you help me?
Thanks!
2 commentaires
Image Analyst
le 12 Déc 2012
How are you capturing these numbers into MATLAB? What's the code? Are you capturing them as numbers? Can't you tell it to store the data into character strings?
Réponse acceptée
Walter Roberson
le 12 Déc 2012
valorsTramaBin_15 = dec2bin(valorsTrama(15,:), 8); %force 8 bits output
Plus de réponses (2)
Arthur
le 12 Déc 2012
Hi!
Try convert the data to a string array before you store in a variable
0 commentaires
Walter Roberson
le 12 Déc 2012
How exactly is the data being received? You say it is binary. Does that mean that for the value 0, it is sending 8 bits (one character) all filled with 0 bits, and for the value 1, it is sending 8 bits with the last of them 1? Or does it mean that for the value 0, it is sending the character '0' (decimal value 48) and for the value 1, it is sending the character '1' (decimal value 49) ?
At some point you appear to be trying to store the number in decimal form. You probably shouldn't be doing that.
If the difficulty you are running into is that there are not enough digits when you display the number or send it somewhere else, and the number is in decimal form, then use
sprintf('%08d', TheNumber')
0 commentaires
Voir également
Catégories
En savoir plus sur Variables dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!