Info
この質問は閉じられています。 編集または回答するには再度開いてください。
Error when calling fucntion
1 回表示 (過去 30 日間)
古いコメントを表示
Hello,
I'm quite new to Matlab and I'm doing a university-course. My assignment is to create a function that for a value x rotates the base vectors of the room in positive direction around the z-axis.
This is what I came up with.
function f=rotate(x)
f=[cos (x), -sin (x), 0; sin (x), cos (x), 0; 0, 0, 1];
But when calling the function rotate for a certain value, let's say rotate(1), it gives me the following errors:
Error using cos
Not enough input arguments.
Error in rotate (line 2)
f=[cos (x), -sin (x), 0; sin (x), cos (x), 0; 0, 0, 1];
I have no idea what to do.
Thanks.
0 件のコメント
回答 (2 件)
Sad Grad Student
2015 年 2 月 22 日
編集済み: Sad Grad Student
2015 年 2 月 22 日
rotate is already an inbuilt matlab function. Change your function name to rotate_val or something else (so it doesn't overwrite the inbuilt function if you need that function in future) and change your saved file name correspondingly. And more important: REMOVE the spaces after cos , sin .. It should be: cos(x) and not cos (x)
This works for me:
function f = rotate_val(x)
f = [cos(x), -sin(x), 0; sin(x), cos(x), 0; 0, 0, 1];
end
>> f = rotate_val(1)
f =
0.54030230586814 -0.841470984807897 0
0.841470984807897 0.54030230586814 0
0 0 1
0 件のコメント
Image Analyst
2015 年 2 月 22 日
Your "x" is really the angle, not the locations. So you should probably call it theta or something. Next you need to pass in an array with the locations like xy which is a 2 by N array of x,y locations. Then you multiply your rotation matrix f by your locations array xy to get "rotated_xy", which you then pass out of the function
function rotated_xy = RotatePoints(xy, theta)
rotationMatrix = .... something involving sind() and cosd() and theta ....
rotated_xy = ... something involving rotationMatrix and xy ......
See if you can complete it.
0 件のコメント
この質問は閉じられています。
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!