index exceed matrix dimension error

조회 수: 4 (최근 30일)
Hamzah amee
Hamzah amee 2014년 1월 13일
댓글: Image Analyst 2014년 1월 14일
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
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).

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by