Effacer les filtres
Effacer les filtres

Accumarray application for rectangle submatices

1 vue (au cours des 30 derniers jours)
Grigorii Nefedov
Grigorii Nefedov le 6 Août 2021
Commenté : Matt J le 6 Août 2021
Is there an elegant way to exclude the for loop from the following function using the accumarray function, for example?
function K = accum(K_size, ...
Pi0, Pi1, Pj0, Pj1, ...
Ki0, Ki1, Kj0, Kj1, ...
psf_arr, psf_ind)
K = zeros(K_size);
for s = 1 : numel(psf_ind)
K( Ki0(s) : Ki1(s), Kj0(s) : Kj1(s) ) = ...
K( Ki0(s) : Ki1(s), Kj0(s) : Kj1(s) ) + ...
psf_arr( Pi0(s) : Pi1(s), Pj0(s) : Pj1(s), psf_ind(s) );
end
end
  6 commentaires
Jan
Jan le 6 Août 2021
Modifié(e) : Jan le 6 Août 2021
@Grigorii Nefedov: Please provide some input data with usual sizes. It matters, if this hould be optimized for millions of loops over small blocks or some loops over huge blocks.
It is tedious to guess, how usual inputs looks in oyur code, but you should be able to create some "meaningful" data with some calls of rand().
Do you want to get an elegenat code, or a fast one? I do not see how avoiding a loop is useful in general.
Matt J
Matt J le 6 Août 2021
If all the rectangles were the same size, I can see how you might make it faster. Otherwise, I think the for-loop is your best bet.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by