フィルターのクリア

How could I solve the problem of if statement for even and odd values?

2 ビュー (過去 30 日間)
Bajdar Nour
Bajdar Nour 2020 年 3 月 31 日
コメント済み: Bajdar Nour 2020 年 3 月 31 日
Whenever I inter any values of N and Z (even-even,odd-even,even-odd,odd-dd) I got only the last result in the condition
here is the code
Z=input('Z: ')
N=input('N: ')
if mod(Z,2)&& mod(N,2)
a=-29.3860;b=-1.1561;c=1.5857;d=0;e=2050;f=0;
elseif mod(Z,2)&& mod(N,1);
a=-29.0583;b=-1.016;c=1.6475;d=0.0426;e=-1.3405;f=6.8970;
elseif mod(Z,1) && mod(N,2);
a=-31.6038;b=-1.0003;c=1.6943;d=2.6263;e=-3.5278;f=-0.0039;
else mod(Z,1)&& mod(N,1);
a=-28.2580;b=-1.0811;c=1.6290;d=0.8047;e=-1.8276;f=3.6070;
end

採用された回答

James Tursa
James Tursa 2020 年 3 月 31 日
mod(N,1) does not determine if a number is even or odd. You would want something like mod(N,2)==0 or mod(N,2)~=0. E.g.,
mod(Z,2)==0 && mod(N,2)==0 % both are even
mod(Z,2)==0 && mod(N,2)~=0 % Z is even, N is odd
etc.
  3 件のコメント
James Tursa
James Tursa 2020 年 3 月 31 日
I just showed you how to code that. What I have written is the actual code for the conditional test. E.g.,
if( mod(Z,2)==0 && mod(N,2)==0 )
% both are even
elseif( mod(Z,2)==0 && mod(N,2)~=0 )
% Z is even and N is odd
etc.
Bajdar Nour
Bajdar Nour 2020 年 3 月 31 日
Thank you so much it works

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by