2D matrix indexing for element wise operation
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Raj Raj
le 19 Fév 2016
Modifié(e) : Star Strider
le 19 Fév 2016
Hello all, I am using following code to estimate pairwise angle between for a vector. Where the angle should be between 0 to 2*pi. I am able to predict the angle. But I need your advise on implementing this two for loops. This is slowing the code. Looking forward for your attention. In the code, XYdata is a n x 2 matrix representing the Cartesian coordinates of individual point [xi, yi]. I presume this slow is because of two FOR loops.
for i2 =1:length(XYdata_new)
for j2 = 1:length(XYdata_new)
angle_ij(i2,j2)= Angle360(XYdata_new(i2,1), XYdata_new(i2,2), XYdata_new(j2,1),XYdata_new(j2,2));
end
end
Thanks in advance.
3 commentaires
Réponse acceptée
Star Strider
le 19 Fév 2016
I would use the atan2 or atan2d functions. They are vectorised, so you can likely give your matrix columns to them directly and then do the angle difference calculations.
8 commentaires
Star Strider
le 19 Fév 2016
Modifié(e) : Star Strider
le 19 Fév 2016
My pleasure!
Thank you.
EDIT — More efficient versions of the angle conversion lines are:
Angles360 = rem(360+a, 360);
Angles2pi = rem(2*pi+a, 2*pi);
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Matrix Indexing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!