What is the best way to convert a vector of integers to binary in simulink?
Afficher commentaires plus anciens
Unfortunately, I do not have the Communications system Toolbox, and I am trying to convert a vector of integers into their binary numbers. I have tried using a 1-D lookup table and a Data Type Conversion box, but I am still not getting the results I am looking for.
Réponses (2)
Azzi Abdelmalek
le 5 Juin 2013
Modifié(e) : Azzi Abdelmalek
le 5 Juin 2013
You can use Matlab function block with this code
function b=decimal2binary(n,nB)
%n your number
%nB number of bits, =16 in your case
n=1852
nB=16
b=2.^[nB-1:-1:0];
bit=zeros(1,nB);
for k=1:numel(b)
if n>=b(k)
bit(k)=1;
n=n-b(k);
end
end
When you can call a Matlab function:
function Bin = toBinary(value, nBit)
Bin = rem(floor(value(:) * pow2((1 - nBit):0)), 2)
Catégories
En savoir plus sur Simulink 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!