would arrayfun work for your code? It would handle both x as a single number and x as a vector, setting 'a' to a single number or a vector to match the input
x = 1;
arrayfun(@(P) P+2, x)
ans =
3
x = [1 2 3 4];
arrayfun(@(P) P+2, x)
ans =
3 4 5 6