Clear Filters
Clear Filters

2 Matrix Multiplications faster than one matrix Multiplication

2 views (last 30 days)
Hello there,
im trying to optimize my program in reducing 2 matrix multiplcations into 1 multiplication like rewrite
for i = 1:10000
filtSig = filtMat * Frame;
recSig = recMat * filtSig:
end
into:
frMat = recMat * filtMat;
for i = 1:10000
recSig = frMat * Frame;
end
Frame is a 128x1 Vector, filtMat is 13x128, recMat is 128x13 and thus frMat is 128x128
when i add tic,toc commands to measure the time, it says that the first version used 16.57ms while the last one uses 25.39ms
My question is, why dose the single Matrix multiplication version much slower than first one?
  5 Comments
Lewei He
Lewei He on 26 Mar 2018
i know that when it gose with compiler languages, have thought matlab makes more optimaze with matrix xD thx for the explanation
dpb
dpb on 26 Mar 2018
Well, Matlab does wonders when you vectorize but even it can't do magic yet. The "Do What I Should Have Done Optimizer" toolbox is yet to be released.
Seriously, remember that there's really no difference between Matlab and any other language under the hood; it has to get translated to procedural code to be executed eventually. The benefit of Matlab syntax is you don't have to write the matrix multiply code loop constructs yourself or call the BLAS libraries directly as in C or Fortran but that's what Matlab is actually doing for you.

Sign in to comment.

Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!