Borrar filtros
Borrar filtros

index exceed matrix dimension error

1 visualización (últimos 30 días)
Hamzah amee
Hamzah amee el 13 de En. de 2014
Comentada: Image Analyst el 14 de En. de 2014
Hi I have this function:
function f = zerocrossmap(blocks);
% This counts the zero cross count for each block % and returns a vector of those values.
len = length(blocks); n = sum(size(blocks)) - len;
f = zeros(n,1);
for i = 1:n f(i) = zerocross(blocks(i,1:len)); end
and function:
function f = block(v, N, M)
% This function separates the vector % into blocks. Each block has size N. % and consecutive blocks differ in % their starting positions by M % % Typically % N = 30 msec (600 samples) % M = 10 msec (200 samples)
n = length(v); maxblockstart = n - N + 1; lastblockstart = maxblockstart - mod(maxblockstart-1 , M);
% Remove the semicolon to see the number of blocks % numblocks = (lastblockstart-1)/M + 1 numblocks = (lastblockstart-1)/M + 1
f = zeros(numblocks,N);
for i = 1:numblocks for j = 1:N f(i,j) = v((i-1)*M+j); end end
so, when I run the funcion like this:
v=wavread('S1M1T01.wav'); N=30; M=10; bl=block(v,N,M) vector=bl; zrcr=zerocross(vector); blocks=bl; z=zerocrossmap(blocks);
I got an error:
Index exceeds matrix dimensions.
Error in zerocrossmap (line 12) f(i) = zerocross(blocks(i,1:len));
Error in block02 (line 8) z=zerocrossmap(blocks);
How to solve this problem?
Thanks a lot

Respuestas (1)

Image Analyst
Image Analyst el 14 de En. de 2014
If len is not 1, then blocks(i,1:len) is a vector of number. Now I don't know what zerocross() is but if it's a array or a function that returns more than 1 number, you can't put it into f(i) because f(i) is just one element - the ith - not a range of elements. For example, you can't stick 10 numbers into a single element (unless it's a cell array, which it's not).

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