You should review the documentation on how to write a function, since your above code is not a correctly written function. First, come up with a name for your function, e.g. myFunction. Then create a new file called myFunction.m somewhere on the MATLAB path (e.g. your working directory). Then in that file put your code. E.g.,
function result = myFunction(V)
result = V;
return
end
I will give you some hints about correcting your code:
Change this loop:
to this
The following test has an error in the logic (compare this carefully with the requirement):
if [V(i)<0 | mod(V(i),2)==0 | mod(V(i),4)==0]
The following line has an error on the right hand side calculation (compare this carefully with the requirement):
If you don't see what the errors are, step through a small example by hand and compare that to the code result. E.g., at the command line type this:
V=[10,4,7,-8,-3,-12];
myFunction(V)
Best Answer