필터 지우기
필터 지우기

Convert formula into coding form

조회 수: 1 (최근 30일)
Syakira Akmal
Syakira Akmal 2017년 4월 1일
답변: Image Analyst 2017년 4월 1일
Hi, i don't know how to convert formula into coding form. Example of formula
theta(kx, ky) = arctan(dy/dx)

답변 (3개)

Star Strider
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
Syakira Akmal
Syakira Akmal 2017년 4월 1일
(kx, ky) is a point. dy = In(kx,ky+1) - In(kx,ky-1) dx = In(kx+1,ky) - In(kx-1,ky)
Star Strider
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
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);

Image Analyst
Image Analyst 2017년 4월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by