Convert formula into coding form
1 次查看(过去 30 天)
显示 更早的评论
Hi, i don't know how to convert formula into coding form. Example of formula
theta(kx, ky) = arctan(dy/dx)
0 个评论
回答(3 个)
Star Strider
2017-4-1
The arguments to the function do not match the arguments to the arctangent function. Are ‘kx’ and ‘ky’ the same as ‘dx’ and ‘dy’ or different?
One of these should do what you want:
theta = @(kx, ky) atan2(ky,kx); % The Values (Or Vectors) Themselves
theta = @(kx, ky) atan2(gradient(ky),gradient(kx)); % The Derivatives Of The Vectors
The atan2 function puts the returned angles in the correct quadrants. The atan function does not.
2 个评论
Star Strider
2017-4-1
My function then changes to:
theta = @(kx, ky) atan2(In(kx,ky+1) - In(kx,ky-1), In(kx+1,ky) - In(kx-1,ky)); % Directly Using ‘In’
That should work.
John D'Errico
2017-4-1
编辑:John D'Errico
2017-4-1
I'd strongly suggest that you start reading the getting started tutorials. This is a very basic question, although I honestly have no idea what it is that you really want to do here. If I had to guess, you need to learn how to write a function.
Using a four quadrant atan, this would do what you want.
theta = @(kx,ky) = atan2(ky,kx);
Or do this:
theta = @(kx,ky) = atan(ky/kx);
0 个评论
Image Analyst
2017-4-1
I agree with John on this: http://www.mathworks.com/matlabcentral/answers/8026-best-way-s-to-master-matlab
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!