"not a valid target for an assignment" problem

"not a valid target for an assignment" problem

Post by Sergey Lit » Thu, 20 Apr 2006 23:47:23



You are using wrong syntax for cycle
Try this

for j = ha:hb
% checks if the program tries to reach out of vector x's bounds
if ( (0 < (j+i+xa1)) && ( (j+i+xa1) < (length(x)+1) ) )
a = h(j+ha1);
b = x(j+i+xa1);
s = a * b;
t = t + s;
end
end
 
 
 

"not a valid target for an assignment" problem

Post by Eren Ayki » Fri, 21 Apr 2006 00:03:40

Thanks a lot Rune and Sergey. I've fixed the problem by your help. My
two main faults were using wrong if statement syntax and using i++, or
++i

Here's the final source code:

xa = input('enter the first input value of function x: ');
xa1 = 1 - xa;
xb = input('enter the last input value of function x: ');
ha = input('enter the first input value of function h: : ');
ha1 = 1 - ha;
hb = input('enter the last input value of function h: : ');
ya = xa + ha;
yb = xb + hb;
tmp = ha;
ha = hb * -1;
hb = tmp * -1;
x = input('output values of function x: ');
h = input('output values of function h: ');
h = fliplr(h);
s = 1;
for i = ya:yb
t = 0;
for j = ha:hb
if ( (0 < (j+i+xa1)) && ( (j+i+xa1) < (length(x)+1) ) )
t = t + h(j+ha1) * x(j+i+xa1);
end
end
y(s) = t;
s = s + 1;
end
stem(ya:yb,y);