How to vectorize the find function?
Afficher commentaires plus anciens
This is my code:
for i=1:size(Z,3)
indmax(i)=find(abs(Z(1,:,i))>z90(1,1,i),1);
indmin(i)=find(abs(Z(1,:,i))>z10(1,1,i),1);
end
trise(:,1)=(t(indmax)-t(indmin));
The variable Z is normally 3 or 6 rows, many columns and 5-10 pages. Something like:
size(Z)= 6 1920 8
The variables z10 and z90 have the same number of rows and pages as Z and 1 column. Something like:
size(z10)=size(z90)=6 1 8
I would actually need to repeat this code 6 more times (1 for each row).
Is there a way to vectorize this?
Réponse acceptée
Plus de réponses (1)
Doug Hull
le 13 Mai 2011
0 votes
Why vectorize?
Just add another for loop for the rows.
4 commentaires
Bernard Küsel
le 13 Mai 2011
Matt Fig
le 13 Mai 2011
You will find that pre-allocating your arrays will speed your code up tremendously if your data is that large.
Doug Hull
le 13 Mai 2011
Your question is then about speeding up the code, not about vectorizing?
Bernard Küsel
le 16 Mai 2011
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!