index exceed matrix dimension error
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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
Antworten (1)
Image Analyst
am 14 Jan. 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).
0 Kommentare
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!