在matlab中围绕y轴旋转3D点

时间:2011-09-15 15:54:11

标签: matlab matrix rotation

我已获得使用旋转矩阵:

matrix

已将矩阵输入我的函数

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

但是只要函数到达此阶段,它就会返回错误

  

???下标索引必须是实数正整数或   逻辑值。

任何非常感谢的帮助

2 个答案:

答案 0 :(得分: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)];

答案 1 :(得分:0)

Ry(theta) 

theta很可能不是真正的正整数或逻辑。

相关问题