Hi I am getting error of unexpected matlab operator in line5 and let me know how to solve it??
1 view (last 30 days)
Show older comments
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
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
Answers (2)
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.
0 Comments
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.
0 Comments
See Also
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!