Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: help in matlab program
Replies: 1   Last Post: Nov 16, 2013 2:11 PM

 Messages: [ Previous | Next ]
 emro87 Posts: 4 Registered: 11/14/13
help in matlab program
Posted: Nov 14, 2013 6:14 AM

Hi.. i am struggling with a problem in matlab that i dont know how to solve, i will be glad if you can help.
-the main cod is:

N=length(data);

L=160; % L/Fs=20ms
M=fix(N/L);
start=1;
stop=L;
En(1)=0
x=zeros(L);
for m=0:(M-1)
x=data(start:stop);
E=energyFunc(x,m,L);

En(m+2)=En(m+1)+E;
start=start+160;
stop=stop+160;

end

-and thats the function code:

function [ D ] = energyFunc( x,m,L )

D=0;
for n=1:L
E=(1/L)*((x(n+m*L)).^2);
D=D+E;
end

end

-I get this error message:

Attempted to access x(161); index out of bounds because
numel(x)=160.

Error in energyFunc (line 6)
E=(1/L)*((x(n+m*L)));

Error in DSPmatlab1 (line 22)
E=energyFunc(x,m,L);

-I dont understand why its out of bounds? i configured the `for` loop from 1 to 160, so `x` should have been in range?
thanks.

Date Subject Author
11/14/13 emro87
11/16/13 emro87