Effacer les filtres
Effacer les filtres

how to Vectorize iterative '' coordinates transformation ''loop operation for speed

4 vues (au cours des 30 derniers jours)
I want to transform local coordinates(tip positions) of a rotating blade into corresponding global coords. Tip coordinates and angular distance changes in time. which means there is a unique transformation matrix for every time step. hence i used loop to multiply transformation matrix (3*3) with local coords to get me global coords each time step. for accuracy reasons i need more than million transformations,which take more than 5 hours with my core i5 computer.its a 2D transformation. i need to vectorize only following part of the code.Please check attachment for complete code.
for i = 1: vec_size
M=[cos(theta_inst(i)) -sin(theta_inst(i)) dx(i);...
sin(theta_inst(i)) cos(theta_inst(i)) dy(i); ...
0 0 1]; %transformation matrix
glbl(1:3,i)= M*local(:,i); % dx,dy ~=0;
end

Réponse acceptée

Matt J
Matt J le 7 Sep 2018
Modifié(e) : Matt J le 7 Sep 2018
In non-homogeneous coordinates,
c=cos(theta_inst(:)).'; s=sin(theta_inst(:)).';
dx=dx(:).'; dy=dy(:).';
L=local(1:2,:);
glbl = [ sum([c;-s].*L) ; sum([+s;c].*L) ]+[dx;dy] ;
  4 commentaires
kamal wisal
kamal wisal le 8 Sep 2018
yes. difference of outputs (global coords) as calculated by iterative process (for loop) and by vectorized operation using sum function.
Matt J
Matt J le 10 Sep 2018
If it's relative error, it is likely due simply to floating point errors.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by