Note that there are some explanatory texts on larger screens.

plurals
  1. PORotation Matrix calculates by column not by row
    text
    copied!<p>I have a class called forest and a property called fixedPositions that stores 100 points (x,y) and they are stored 250x2 (rows x columns) in MatLab. When I select 'fixedPositions', I can click scatter and it will plot the points. </p> <p>Now, I want to rotate the plotted points and I have a rotation matrix that will allow me to do that.</p> <p>The below code should work:</p> <p>theta = obj.heading * pi/180; apparent = [cos(theta) -sin(theta) ; sin(theta) cos(theta)] * obj.fixedPositions;</p> <p>But it wont. I get this error.</p> <p>??? Error using ==> mtimes Inner matrix dimensions must agree.</p> <p>Error in ==> landmarks>landmarks.get.apparentPositions at 22 apparent = [cos(theta) -sin(theta) ; sin(theta) cos(theta)] * obj.fixedPositions;</p> <p>When I alter forest.fixedPositions to store the variables 2x250 instead of 250x2, the above code will work, but it wont plot. I'm going to be plotting fixedPositions constantly in a simulation, so I'd prefer to leave it as it, and make the rotation work instead.</p> <p>Any ideas?</p> <p>Also, fixed positions, is the position of the xy points as if you were looking straight ahead. i.e. heading = 0. heading is set to 45, meaning I want to rotate points clockwise 45 degrees. </p> <p>Here is my code:</p> <pre><code>classdef landmarks properties fixedPositions %# positions in a fixed coordinate system. [x, y] heading = 45; %# direction in which the robot is facing end properties (Dependent) apparentPositions end methods function obj = landmarks(numberOfTrees) %# randomly generates numberOfTrees amount of x,y coordinates and set %the array or matrix (not sure which) to fixedPositions obj.fixedPositions = 100 * rand([numberOfTrees,2]) .* sign(rand([numberOfTrees,2]) - 0.5); end function apparent = get.apparentPositions(obj) %# rotate obj.positions using obj.facing to generate the output theta = obj.heading * pi/180; apparent = [cos(theta) -sin(theta) ; sin(theta) cos(theta)] * obj.fixedPositions; end end end </code></pre> <p>P.S. If you change one line to this: obj.fixedPositions = 100 * rand([2,numberOfTrees]) .* sign(rand([2,numberOfTrees]) - 0.5);</p> <p>Everything will work fine... it just wont plot. </p> <p>ans = obj.fixedPositions; ans'; will flip it to what I need to plot, but there has to be a way to avoid this? </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload