bsxfun to multiply matrix with vector multiple times in for loop --> how faster?

1 Ansicht (letzte 30 Tage)
T
T am 6 Mär. 2017
Bearbeitet: Matt J am 10 Mär. 2017
I have a 2D matrix of size NxN, and each row I am multiplying with a 1xN vector with bsxfun in a for loop like this:
for k=1:1000
b(k)=mean(bsxfun(@times,tb_filter2d,d(k,:)),2);
end
Is there a way to speed this up? d is of the size 1000xN.
Thank you!!
  4 Kommentare
James Tursa
James Tursa am 6 Mär. 2017
If tb_filter2d is your NxN matrix, how does this even work since the result of the RHS is a vector and you are assigning it to a scalar element location b(k)?
Rik
Rik am 6 Mär. 2017
Is there a reason you can't use something like meshgrid to remove the loop?

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Ankita Nargundkar
Ankita Nargundkar am 9 Mär. 2017
1. If you are on MATLAB R2016b, you can use operators directly instead of bsxfun. Refer to this example
2. You can use repmat or reshape to optimize. Refer to this link
Something on similar lines, https://www.mathworks.com/matlabcentral/answers/210352-optimize-speed-up-a-big-and-slow-matrix-operation-with-addition-and-bsxfun

Matt J
Matt J am 10 Mär. 2017
Bearbeitet: Matt J am 10 Mär. 2017
This shouldn't require more than a single vector-matrix multiplication,
result =(tb_filter2d/N)*d.';

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by