How NOT remove zeros from binary number?
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Image Analyst
il 12 Dic 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?
Risposta accettata
Walter Roberson
il 12 Dic 2012
valorsTramaBin_15 = dec2bin(valorsTrama(15,:), 8); %force 8 bits output
Più risposte (2)
Arthur
il 12 Dic 2012
Hi!
Try convert the data to a string array before you store in a variable
0 Commenti
Walter Roberson
il 12 Dic 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 Commenti
Vedere anche
Categorie
Scopri di più su Variables in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!