How to divide a 3d matrix by a 2d matrix along one dimension

12 vues (au cours des 30 derniers jours)
Tillmann Spellauge
Tillmann Spellauge le 23 Août 2018
Commenté : Star Strider le 23 Août 2018
Hi everybody,
I have 3d Matrix named Data, consisting of several grey scale Pictures. I want to divide it by a 2d Matix called DataMax containing the maximum intensity among the pictures at a pixel, in order to normalize Data in the 3rd dimension to 1.
I can perform the operation using a for loop:
DataMax = max(Data,[],3);
[x,y,z] = size(Data);
for k=1:z
Data(:,:,k) = Data(:,:,k)./DataMax;
end
However I would like to get rid of the loop in order to maximize performance.
Any ideas on how to do this?

Réponse acceptée

Star Strider
Star Strider le 23 Août 2018
See if bsxfun (link) will do what you want:
Data = bsxfun(@rdivide, Data, DataMax);
It is generally quite efficient.
  2 commentaires
Tillmann Spellauge
Tillmann Spellauge le 23 Août 2018
Works like a charm! Thanks a lot!
Star Strider
Star Strider le 23 Août 2018
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by