conversion from binary to decimal

4 vues (au cours des 30 derniers jours)
God'sSon
God'sSon le 16 Mai 2011
Hello, I am trying to perform binary to decimal conversion somewhere in my code and I get the following error message. can someone please help.
item=bits(i,:));% item is a row gotten from the array named bits
scale=bin2dec('item');
??? Error using ==> bin2dec at 54 Binary string may consist only of characters 0 and 1
Error in ==> QUANTIZATION_BLOCK at 121 scale=bin2dec('item');
Thanks.

Réponse acceptée

Walter Roberson
Walter Roberson le 16 Mai 2011
First of all, it would be
scale = bin2dec(item); %no quotes!
Secondly, your bit values are probably values of 0 and 1, whereas bin2dec needs values of '0' and '1'
item = char('0' + bits(i,:));
  1 commentaire
God'sSon
God'sSon le 16 Mai 2011
Thanks Walter.

Connectez-vous pour commenter.

Plus de réponses (1)

Paulo Silva
Paulo Silva le 16 Mai 2011
item=bits(i,:));% item is a row gotten from the array named bits
scale=bin2dec(item);
Just removed those '', you want what's inside the variable called item not the string item
  1 commentaire
God'sSon
God'sSon le 16 Mai 2011
Thanks Paulo

Connectez-vous pour commenter.

Catégories

En savoir plus sur Data Type Conversion 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!

Translated by