Hi I am getting error of unexpected matlab operator in line5 and let me know how to solve it??

1 view (last 30 days)
function [y Ny]=convo2(x,Nx,h,Nh)
Ny=Nx+Nh;
for n=0:Ny
y(n+1)=0;
for k+1=1:Nh
for m+1=1:Nx
n=k+m;
y(n+1)=y(n+1)+h(k+1)*x(m+1);
end
end
end
  1 Comment
dpb
dpb on 18 Jun 2014
Format the code, please...
function [y Ny]=convo2(x,Nx,h,Nh)
Ny=Nx+Nh;
for n=0:Ny
y(n+1)=0;
for k+1=1:Nh
for m+1=1:Nx
n=k+m;
y(n+1)=y(n+1)+h(k+1)*x(m+1);
end
end
end

Sign in to comment.

Answers (2)

dpb
dpb on 18 Jun 2014
...
for k+1=1:Nh
for m+1=1:Nx
...
are illegal syntax. If you mean for k and m to start from 2, then write the loop over
for k=2:Nh-1
etc., or recast similarly as to your loop over n
NB: the assignment to y() inside the loop w/o preallocating will be very inefficient.

Star Strider
Star Strider on 18 Jun 2014
You actually have two problems:
for k+1=1:Nh
for m+1=1:Nx
This is not a permitted construction.
Restate them as:
for k=1:Nh
for m=1:Nx
and adjust your subscript indices to get the result you want.

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!