Why I will get error:Index exceeds matrix dimensions

1 visualización (últimos 30 días)
MING LIANG WANG
MING LIANG WANG el 22 de Mayo de 2018
Editada: Guillaume el 22 de Mayo de 2018
I don't know why modulated(200*(index-1)+1, 200*index); will cause index exceeds matrix dimension error.
I want to cut vector modulated into ten thousand components with 200 bits in each.
And it depends on random binary vector with size is num_bit(is 10000 in this case).
num_bit = 10^4;
modulated = zeros(1, 200*num_bit); %use 200 plot to describe one symbol
for index = 1:num_bit
if messenge(index) == 1
modulated(200*(index-1)+1, 200*index);
%modulated(200*(index-1)+1, 200*index) = ones(1, 200);
elseif messenge(index) == 0
%modulated(200*(index-1)+1, 200*index) = zeros(1, 200);
end
end

Respuesta aceptada

Guillaume
Guillaume el 22 de Mayo de 2018
Editada: Guillaume el 22 de Mayo de 2018
I'm not sure what you're trying to achieve. However,
modulated = zeros(1, 200*num_bit)
crates an array with 1 rows and plenty of columns
modulated(200*(index-1)+1, 200*index)
tries to access rows 1, 201, 401, ... of the array which has only 1 row as you created it. So, of course index exceeds dimension
Note that even if the index was valid, as it is the line is pointless since you don't do anything with the value you've read.

Más respuestas (1)

Nicola Bombace
Nicola Bombace el 22 de Mayo de 2018
The error is because at line 2 you initialise your matix with just one row, and later (at line 6) you try to access an index bigger than one.
An easy fix would be changing the line 2 in modulated = zeros(200*num_bit);

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by