Your program is on the right track, but the problem is your are trying to access elements of x which do not exist, i.e x(5) and so on.
So to avoid this problem adjust the length of x and h to be equivalent to the final length as shown:-
n=6;
x=[1 2 2 3 0 0];
h=[2 -1 3 0 0 0];
y=zeros(1,n);
for i=1:n
for j=1:i
y(i)=y(i)+x(j)*h(i-j+1)
end
end
So both x and h are now of length 6.
Another option would be to take x and h and then later append zeroes to it to make their lengths equal to 6, such as:-
n=6;
x=[1 2 2 3];
h=[2 -1 3];
x=[x zeros(1,6-length(x))];
h=[h zeros(1,6-length(h))];
y=zeros(1,n);
for i=1:n
for j=1:i
y(i)=y(i)+x(j)*h(i-j+1)
end
end