필터 지우기
필터 지우기

Solving Mathematical Relation Having If and Else Statement in Matlab

조회 수: 2 (최근 30일)
Hi,
Here I am writing a mathematical relation which is needed to be solved using Matlab:
N=4;
j=sqrt(-1);
Sx=[27 0 4 19;
19 -8 -10 16;
20 -4 -7 9;
27 0 2 24];
Sy=[22 4 -7 -25;
7 2 -8 -12;
-8 -5 3 5;
-23 -9 5 13];
P(k,l)={0; if k,l=0 and k,l=N/2
{((exp(-j*2*pi*k)/N)-1)*((exp(-j*2*pi*l)/N)+1)*DFT(Sx(k,l)+
((exp(-j*2*pi*l)/N)-1)*((exp(-j*2*pi*k)/N)+1)*DFT(Sy(k,l)}*
{8*((sin(k*pi/N).^2)*(cos(l*pi/N).^2)+(sin(l*pi/N).^2)*(cos(k*pi/N).^2)}.^(-1), else
where k and l varies from 1 to 4 each
********** Can anyone please help me in solving the above problem with the help of Matlab? Thanking You!
  댓글 수: 4
Image Analyst
Image Analyst 2013년 9월 17일
What variable(s) are you solving for? What is the unknown(s)?
Pranjal Pathak
Pranjal Pathak 2013년 9월 18일
I need to write a code to solve for the variable P(k,l).
Thanks.

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2013년 9월 18일
Well you are practically there already. Just put that code in a loop over k and l (l is a bad variable name choice). Inside the loop have the if statements where you assign P(k,l) to different things depending on what the values of k and l are.
  댓글 수: 2
Pranjal Pathak
Pranjal Pathak 2013년 9월 18일
Thanks a lot for your suggestions. I tried, but it is showing some error when I run it. Could you please figure out the problem? Here is the code:
Sx=[27 0 4 19; 19 -8 -10 16; 20 -4 -7 9; 27 0 2 24];
Sy=[22 4 -7 -25; 7 2 -8 -12; -8 -5 3 5; -23 -9 5 13];
n=4; j=sqrt(-1);
P=zeros(n,n); for k=1:n for m=1:n Ftx=fft2(Sx); Fty=fft2(Sy);
if((k == 0 | m == 0) & (k == n/2 | m == n/2))
P(k,m)=0;
else
P(k,m)=((((exp(-j*2*pi*k)/n)-1)*((exp(-j*2*pi*m)/n)+1)*Ftx)+(((exp(-j*2*pi*m)/n)-1)*((exp(-j*2*pi*k)/n)+1)*Fty)*(8*((sin(k*pi/n)^2)*(cos(m*pi/n)^2)+(sin(m*pi/n)^2)*(cos(k*pi/n)^2))^(-1)));
end
end
end
P(k,m); *************** Thanks.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by