How to convert a vector into bitstring?
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
How to convert a vector into bitstring in matlab?
0 Commenti
Risposte (2)
Thorsten
il 29 Giu 2015
Vector = [255 1 0];
reshape(dec2bin(Vector)', 1, [])
1 Commento
Walter Roberson
il 29 Giu 2015
In general the length of that is not certain. dec2bin() will by default use the number of bits per row that is the number of bits required to represent max() of the data, so if all of your data happened to be in the range 0 to 63 (for example) then the result would be only 6 bits per entry. But your receiver doesn't usually know ahead of time what the restricted range will be so it is safer to force the use of the number of bits required for the maximum potential value.
Secondly this code assumes that the data is non-negative and that any floating point numbers should be rounded to the nearest integers. That might turn out to be a valid assumption for the purposes of the poster, but the more general case would require that floating point numbers be pulled apart for reconstruction in full precision on the other side; the code in my answer does that.
Vedere anche
Categorie
Scopri di più su Data Type Conversion 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!