MATLAB: How to output a vector/array from a created function

output

In short, I have an array that has numbers from 0 to 100 using a step of 0.01, I created a function that is supposed to output another array containing 1's and -2's. While looping on the indices of my first array if the number is smaller than 40, I insert 1 in my output array, otherwise I insert a -2. I don't know what's the problem in my code:
function [outputVector] = myOutput(inputVector)
outputVector = [];
for i=1 : size(inputVector)
if inputVector(i) < 40
outputVector = [outputVector,1] ;
else
outputVector = [outputVector,-2];
end
end
end

Best Answer

The vector that you would be creating using 0 : 0.01 : 100 would have a size of 1x10001.
>> size(0 : 0.01 : 100)
ans =
1 10001
Your for loop on the size returns the first dimension whereas you require the second dimension.
Changing
for i=1 : size(inputVector)
to
for i=1 : size(inputVector, 2)
should work for you.