sub-array

Find the first occurrence/starting index of the sub-array in C#.

Given two arrays as parameters (x and y) and find the starting index where the first occurrence of y in x. I am wondering what the simplest or the fatest implementation would be. Example: when x = {1,2,4,2,3,4,5,6} y = {2,3} result starting index should be 3 Updated: since my code is crap I removed it from the question...

MATLAB - having trouble with sub-array

I am trying to sub-array in MATLAB with no luck. This is what I am doing: a = randint(latticeSize, 1, [0 1]); % a 1st attempt which works but sucks localPattern = [a(i-1) a(i) a(i+1)]; The above works fine but I want to generalize it with something like: % this is how I'd like to do it as more general localPattern = a(i-1 : i+1); ...