0

I'm using Matlab 2013a on Windows 7 Pro 64 bit.

In 2010 (using a different version of Matlab), I wrote the following code to calculate a 3x3 rotation matrix

C=rotate (omega, i, w);
R=C*Ro;

where omega, i, and w are rotation angles in radians. On my current system, giving the example input of omega = i = w = 0, C will be a 3x3 identity matrix.

If I copy the code into another directory that I wrote in the past few months, the same code will result in the following error.

Error using rotate
Too many output arguments.

So my question to SO is why the same lines of code on the same computer with the same version of Matlab will work in one directory but not in another directory?

tshepang
  • 12,111
  • 21
  • 91
  • 136
Ryan
  • 3
  • 1
  • 2
  • 1
    To avoid confusions, why not name your function to something other than `rotate` as it matches with MATLAB's in-built function that does something else. – Divakar May 04 '14 at 22:31
  • I am trying to use the built-in Matlab function 'rotate'. The problem I'm having is that 'rotate' behaves differently in different directories on my computer. – Ryan May 05 '14 at 02:32
  • 1
    Take a look here - http://www.mathworks.in/help/matlab/ref/rotate.html. This is the in-built-one MATLAB function and it appears to use the first parameter as the figure handle. You mentioned using `omega` as the first parameter as a rotation angle. – Divakar May 05 '14 at 03:57
  • You could try [which rotate](http://www.mathworks.com/help/matlab/ref/which.html) in your code in both directories to check whether they're using the same `rotate`. I suspect that the original directory has a `rotate` function in it that is overriding Matlab's version. – beaker May 05 '14 at 16:29
  • beaker, you and Divakar figured it out. I had written a function that inputted the rotation angles and outputted a rotation matrix, but named it the same as a built-in Matlab function. If you add an answer below, I'll up vote it and select it as the accepted answer. – Ryan May 08 '14 at 01:49

1 Answers1

0

If you had read the help for rotate, you would have seen that this one does not calculate the rotation matrix, but rotates a matlab graph. Some toolboxes eg Phased Array System Toolbox have some functions rotx, roty,... to calculate the rotational matrix.

However, functions for calculating the rotation matrix is not that hard to construct. Looking at http://en.wikipedia.org/wiki/Rotation_matrix the rotational matrices for every axis is given. The general rotation matrix is then a product of the individual rotation matrices. This should be piece of cake.

patrik
  • 4,506
  • 6
  • 24
  • 48