Newbie question - Error in line 2

14 views (last 30 days)
Jonas Persson
Jonas Persson on 20 Feb 2018
Edited: Jim Riggs on 21 Feb 2018
Sorry to ask a really newbie question. Does anyone know why the attached does not work?
  2 Comments
Star Strider
Star Strider on 20 Feb 2018
It appears that you are coding your own rotation matrix. I do not see any obvious errors.
I cannot run an image of your code, only posted and properly formatted code, so I cannot test it.
How are you calling it?
What about it is not working?
Jim Riggs
Jim Riggs on 21 Feb 2018
I see an error. See my comment, below.

Sign in to comment.

Answers (2)

Walter Roberson
Walter Roberson on 20 Feb 2018
The error message itself did not get included, but I suspect that you tried to click Run to run the code. You need to save the file and then invoke the code from the command line, providing a value for the argument. For example,
AbvMa(pi/7)
  4 Comments
Jonas Persson
Jonas Persson on 20 Feb 2018
I am extremely grateful for the answer and sorry for being such a newbie. Could you help me with the syntax? I will not ask any more after that..
Image Analyst
Image Analyst on 20 Feb 2018
Get rid of the line
>> y = AbvMa(pi/7)
from your m-file, and call that from the command line.
y = AbvMa(pi/7)
Or else put it at the very top of the m-file, above the function line.

Sign in to comment.


Jim Riggs
Jim Riggs on 21 Feb 2018
Edited: Jim Riggs on 21 Feb 2018
Your equation set looks like it produces a direction cosine matrix for a planar rotation about the Z axis. If this is the case, your notation is rather confusing, and there is a sign error in one of the terms. Your solution
y = [x1 x2 -x3; y1 y2 y3; x3 y3 z3]
gives the following matrix:
cos(v) sin(v) 0
sin(v) cos(v) 0
0 0 1
Note that you have put a minus sign on a term x3, which is zero. If you desire to construct a direction cosine matrix for a z-axis rotation, one of the sin(v) terms should be negated (depending on the direction of the rotation)
It would be much more clear (and concise) to build your function something like the following;
sinv=sin(v);
cosv=cos(v);
y = [cosv -sinv 0; sinv cosv 0; 0 0 1];

Categories

Find more on MATLAB Report Generator in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!