2011-09-15 85 views
1

我已經提供了一個旋轉矩陣使用方法:旋轉圍繞y軸的三維點在MATLAB

matrix

,並已進入了矩陣到我的功能

theta = radians(theta); 
Ry(theta) = [cos(theta) 0 sin(theta); 0 1 0; -sin(theta) 0 cos(theta)]; 
newpose = pos*Ry(theta); 

還只要功能達到此階段,就會返回錯誤

???下標索引必須是實數正整數或邏輯數。

任何幫助非常感謝

+0

另請參閱[這個問題](http://stackoverflow.com/questions/20054047/subscript-indices- (對於這個問題的通用解決方案)(http://stackoverflow.com/a/20054048/983722),必須是任意正整數或邏輯通用解。 –

回答

1

問題是Ry(theta)。如果你想把它作爲一個變量,或者把它放在一個實際的函數中,就稱之爲Ry_theta。這應該工作:

theta = radians(theta); 
Ry_theta = [cos(theta) 0 sin(theta); 0 1 0; -sin(theta) 0 cos(theta)]; 
newpose = pos*Ry_theta; 

或者 - 如果你想有一個更可重複使用的解決方案:

% in your existing file: 
theta = radians(theta); 
newpose = pos*rotationAboutYAxis(theta);; 

% in a file called rotationAboutYAxis.m: 
function Ry = rotationAboutYAxis(theta) 
Ry = [cos(theta) 0 sin(theta); 0 1 0; -sin(theta) 0 cos(theta)]; 
0
Ry(theta) 

theta是最有可能不是真正的正整數或邏輯。