I need help with this matlab code... I look for help in Chegg and the answer is
ID: 3804521 • Letter: I
Question
I need help with this matlab code...
I look for help in Chegg and the answer
is giving in this link (please, visit the link:
http://www.chegg.com/homework-help/questions-and-answers/polytechnic-university-puerto-rico-electrical-computer-engineering-computer-science-depart-q19487728 )
But when I try this code given as a "solution" for the statement in Chegg...
The Matlab software trigger an error:
"function [y]= sumbothends (×, L)
ERROR: Function definitions are not permitted in this context..."
(see picture attached).
Please HELP ME!!! I need the help rush...
thanks!!
Explanation / Answer
Create 2 files
1) driver.m
2) sumbothends.m
And run driver.m after pasting following codes into respective files!
sumbothends.m
function [y]= sumbothends (x, L)
if(L <= 0 || L > size(x,2) )
fprintf('Invalid input! ') ;
else
y = [sum(x(1:L)) , sum( x( (size(x,2) -L+1) : size(x,2) ))];
end
end
driver.m
y = sumbothends([3,2,-1,3, 2,1,3],3);
y
Sample Output: