MATLAB: Matrix multiplication in 4 D

loopmatrix

I have two matrices. The x(r,i,t1,t2) and y(t1) matrix. I want to multiply the matrix y in matrix x for all r, i, and t2. I have the following codes and errors. Could you please help me to realize what is the problem.
R=8;
I=12;
T1=11;
T2=10;
x=rand(R,I,T,TT);
y =[99 129 115 128 96 94 98 107 133 99 120];
for r=1:R
for i=1:I
for t2=1:T2
for t1= 1: T1
xnew(r,i,t1,t2)=y(t1).*x(r,i,t1,t2);
end
end
end
end
Error
Undefined function 'y' for input arguments of type 'double'.
Error in test (line 12)
xnew(r,i,t1,t2)=y(t1).*x(r,i,t1,t2);

Best Answer

If I replace
x=rand(R,I,T,TT);
with
x=rand(R,I,T1,T2);
your code runs to completion for me.