index exceed matrix dimension error
1 次查看(过去 30 天)
显示 更早的评论
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
回答(1 个)
Image Analyst
2014-1-14
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!