x = [1; 2]

y = rot90 (x)

Gives y = [1 2] but answer should be [-2; 1] D-: help plz

x = [1; 2]

y = rot90 (x)

Gives y = [1 2] but answer should be [-2; 1] D-: help plz

The function `rot90`

just rotates an array 90°, so that, like in your example, a column vector becomes a row vector, but does not change the values in the array.

Could you explain how you think [-2; 1] should be the result of a 90° rotation?

1 Like

Like @pantxo already wrote, `rot90`

permutes the first two dimensions of an array. It doesn’t perform a matrix rotation in a geometrical sense.

Afaict, there are no built-in functions for matrix rotation in Octave.

IIUC, you’d like to rotate in 2d Euclidean space. In that case, you could define a function like this:

```
function out = rot2d (in, angle)
# Rotate 2d column vectors IN by ANGLE in degrees
rot = [cosd(angle), -sind(angle); sind(angle), cosd(angle)];
out = rot * in;
endfunction
```

With that function, you’d get the result you expected with `rot2d (x, 90)`

.

1 Like

Yeah. The name of the function is a bit unfortunate. But we need to keep it for compatibility with code written for Matlab.