Let's call the array
x = 2 4 6 8 1 9 7 5 3
I'm assuming you don't have the array stored in a variable (in which case this question boils down do:
find(x==z)), and that you don't need the array either (in which case this question is really: "How do I create
length as a variable name.
length is a builtin function, and overloading it is a bad idea. Although it's better to use the builtin
numel instead of
length is not a good idea. It might cause all sorts of strange bugs. Choose another variable name (I'll use
len, you might use something else).
x has a fairly straight forward setup, and can be created quite simply using concatenation and the colon operator.
x = [2:2:len, 1, fliplr(3:2:len)]
If you can guarantee that
len is odd then it's simply:
x = [2:2:len, 1, len:-2:3]
Now, you have
x, and you know
z. The only thing remaining is a simple call to
col = find(x==z);