Selecting part of each row from a bigger matrix without loops

1 vue (au cours des 30 derniers jours)
Pooya Poolad
Pooya Poolad le 15 Nov 2019
Commenté : Athul Prakash le 20 Nov 2019
Hello there,
I have matrix h, let say it is 10,000x1000. I want to somehow select some known part of each column. these parts are in different sizes but all start from first element of the column. Then I want to partition these selections to form a final array of, for instance (20,1000);
currently I'm doing that using a for loop, but it has became a bottleneck in my script (as all other parts are vectorized):
%duration is an array that says how many element of each column is needed
for i = 1:size(h,2)
temp = h(1:uint32(duration(i)/delta),i);
h_select(:,i) = sum(reshape(temp,size(temp,1)/histogram_bins,histogram_bins,size(temp,2)));
end
The other problem is if I create a zeros matrix with size of ((longest selection)x1000) in this example and just do the same reshaping and sum to have (20x1000) answer, the shortest one would actually loose its resolution as "histogram_bins" in the code is fixed. So for the longest selection I will end up with 20 valid values but for shortest one I might end up with 2 valid values and 18 zeros.
I would be appreciated if anyone have an idea what is the fastest way to deal with this situation.
  1 commentaire
Athul Prakash
Athul Prakash le 20 Nov 2019
Hey, the code you've shown is not easily vectorizable, not without making it fairly more complex.
I think you should try parfor, if you have the parallel computing toolbox installed. That way you can run the same for loop in parallel across many cores. Please have a look here:
Since parfor does come with a few contraints, you will need to make a few tweaks to your code. Once again, documentation will help you.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by