MATLAB: How to optimize this matlab code

vectorization

I am new to matlab and trying to optimize this matlab code through optimization
function X = DWT2DCT(x,Dct_matrix,W_matrix)
[M,N,K]=size(x);
y = zeros(K,M*N);
X = zeros(K,M*N);
temp = zeros(M,N);
for k=1:K
temp = W_matrix*x(:,:,k)*W_matrix';
y(k,:)=temp(:)';
end
X = Dct_matrix*y;
Till now I explored that it is possible through vectorization and this loop can be vectorized can someone please guide me

Best Answer

Use multiprod as follows:
y = reshape(multiprod(multiprod(W_matrix, x), W_matrix'), [], K)';
It is an M-code file without for loops.
Related Question