[Signal Processing] In an assignment A(I) = B, the number of elements in B and I must be the same.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Tien T
el 29 de Mayo de 2014
Comentada: Star Strider
el 29 de Mayo de 2014
The following code gives the error, "In an assignment A(I) = B, the number of elements in B and I must be the same." due to the last line of code.
numSamples = 10; % Number of samples
pulseShape = ones([0,numSamples]); % Generate a series of impulses
numBits = 1e6; % Number of input bits
bits = randi([0 1],numBits,1); % Generate a million random binary bits
bits(bits==0) = -1; % Modulate signal to BPSK
waveformBPSK = zeros([0,numBits .* numSamples]); % Creates signal spectrum
% Convolutes input pulses with spectrum at every sampled value; convert all
% bits at sampled values to be the corresponding input bit value.
waveformBPSK(1:numSamples:end) = bits;
In general, I would like to convert the zero values of the vector waveformBPSK at the values of numSamples to its corresponding bit values (generated randomly by bits).
It looks to me if the problem is because the program sees that bits is still a vector of 1 million values and cannot convert each value of the waveformBPSK to the bits vector. However, I would like to convert each zero value of the vector waveformBPSK at the sampled value of numSamples to each individual value of bits.
Cheers!
0 comentarios
Respuesta aceptada
Star Strider
el 29 de Mayo de 2014
What would we do without accumarray?
Replace the last line in your code with these two:
z = accumarray( [1:numSamples:size(waveformBPSK,2)]', bits, [], @(x) x);
waveformBPSK = z;
They produce a column vector, so transpose to row if necessary.
4 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre BPSK en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!