MATLAB: How to optimize this matlab code


I am new to matlab and trying to optimize this matlab code through optimization
function X = DWT2DCT(x,Dct_matrix,W_matrix)
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';
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.