So problem 1 is that size is outputting a vector and not a single value. It outputs both dimensions so for your example m is [1 9] which will not work in the if statements as written. Since you know v is a vector then the easiest change here is to change that line to
2) in your elseif you have n<-m which makes no sense. I expect you might have meant n<=m but that is really unnecessary anyways and you can remove that entirely to just be an else statement.
3) I do not know what you are trying to do with
but I do not think it will work. I would do it as such:
summa = 0;
if summa < sum(v(v1:v1+n-1))
summa = sum(v(v1:v1+n-1));
For index do you want the output to be the actual indices [4 5 6] that the largest values occur or the largest values. If you want the largest values and not the indices simply replace the line with this: