multiplication of matrix with long data
    8 ビュー (過去 30 日間)
  
       古いコメントを表示
    
Hi,
I have a long data (200K+ samples) from which a location vector L (3x1) and a matrix T (euler matrix 3x3) is generated and multiplied l = TL.
On the results of l (3x1) there are operations of sin and atan (to get the required results).
So far, I'm doing a for loop, which is not a Matlab way. 
I'd like to speedup the performance of the code.
How can I do it?
4 件のコメント
  Bruno Luong
      
      
 2022 年 7 月 14 日
				"So far, I'm doing a for loop, which is not a Matlab way. "
Anything allowed by MATLAB IS MATLAB way.
  Steven Lord
    
      
 2023 年 2 月 28 日
				Is there a specific reason you're still using release R14SP2 which is pretty close to twenty years old at this point?
There have been a lot of improvements in MATLAB in the past twenty years, which likely would improve performance of your code.
採用された回答
  Bruno Luong
      
      
 2022 年 7 月 14 日
        
      編集済み: Bruno Luong
      
      
 2022 年 7 月 14 日
  
      % Test data
N = 4;
Phi     = 2*pi*rand(1,N);
Theta   = 2*pi*rand(1,N);
Psi     = 2*pi*rand(1,N);
X       = rand(1,N);
Y       = rand(1,N);
Z       = rand(1,N);
Phi     = reshape(Phi,      1, 1, []);
Theta   = reshape(Theta,    1, 1, []);
Psi     = reshape(Psi,      1, 1, []);
X       = reshape(X,        1, 1, []);
Y       = reshape(Y,        1, 1, []);
Z       = reshape(Z,        1, 1, []);
sB = sin(Phi);   cB = cos(Phi);
sD = sin(Theta); cD = cos(Theta);
sE = sin(Psi);   cE = cos(Psi);
T = [ cD.*cE, -cB.*sE+cE.*sB.*sD,  sB.*sE+cB.*sD.*cE;
      cD.*sE,  cB.*cE+sB.*sD.*sE, -cE.*sB+cB.*sD.*sE;
         -sD,             sB.*cD,             cB.*cD ];
XYZ = [X; Y; Z];
xyz = pagemtimes(T, XYZ)
% For older MATLAB
%XYZ = [X, Y, Z];
%xyz = sum(T.*XYZ,2)
7 件のコメント
  Bruno Luong
      
      
 2023 年 2 月 28 日
				
      編集済み: Bruno Luong
      
      
 2023 年 2 月 28 日
  
			The inverse of T is its transpose T.', you need to form the inverse, noted here by iT
iT = [ cD.*cE,             cD.*sE,            -sD;
      -cB.*sE+cE.*sB.*sD,  cB.*cE+sB.*sD.*sE, sB.*cD;
       sB.*sE+cB.*sD.*cE,  cE.*sB+cB.*sD.*sE, cB.*cD ];
% For older MATLAB
XYZ = [X, Y, Z];
xyz = sum(iT.*XYZ,2)
その他の回答 (0 件)
参考
カテゴリ
				Help Center および File Exchange で Logical についてさらに検索
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



