Creating a Array of binary values

2 views (last 30 days)
João Filipe Silva
João Filipe Silva on 8 Sep 2015
Edited: Geoff Hayes on 9 Sep 2015
I'm trying to do the quantization of a wav file on Matlab, but I'm struggling to get this function right.
Quant = zeros(1,length(y));
Q = peak2peak(y);
N = 2^8;
Delta = double(Q)/double(N); %Analog aproximation of each value on y
Faixa = 0:Delta:double(Q)-Delta; %Array of 256 analog values
for k1 = 1:length(y)
for k2 = 1:N-1
if (y(k1)>Faixa(k2) && y(k1)<=Faixa(k2+1))
Quant(k1) = dec2bin(k2,8); %Saving on array Quant the binary value corresponding to its analog comparison
break
end
end
end
Y has 16000 values, and I'm getting the following message: In an assignment A(I) = B, the number of elements in B and I must be the same.
  1 Comment
Matthew Eicholtz
Matthew Eicholtz on 8 Sep 2015
The reason you are getting that error is because you are trying to store an 8-bit binary string (dec2bin(k2,8)) in a double array index with 1 row ( Quant(k1)). MATLAB does not like this.
I'm not sure what you want Quant to look like, but 2 options are:
  1. Make Quant a cell array of length(y) and store the binary strings in each cell.
  2. Make Quant have 8 rows (or columns depending on your desires), and store the 8-bits that way.

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!