フィルターのクリア

Write a function called holiday that takes two input arguments called month and day; both are scalar integers representing a month (1-12) and a day (1-31). You do not need to check that the input is valid. The function returns a logical true if the s

1 回表示 (過去 30 日間)
function [v] = holiday(day,month)
a=[1,1];
b=[4,7];
c=[25,12];
d=[31,12];
A= [day,month]
if A == a | A == b | A == c |A == d
v= true
else
v=false
end
here i'm getting an error with input(7,4) . any idea why? the format for the code being(day,month) is adhered to.

回答 (5 件)

Stephan
Stephan 2018 年 6 月 6 日
編集済み: Stephan 2018 年 6 月 6 日
Hi,
Your condtion is A = [4,7] --> you tried [7,4]:
function [v] = holiday(day,month)
a=[1,1];
b=[4,7];
c=[25,12];
d=[31,12];
A = [day,month]
if A == a | A == b | A == c |A == d
v= true;
else
v=false;
end
v
check for x = holiday(4,7):
x = holiday(4,7)
v =
logical
1
x =
logical
1
check for y = holiday(7,4):
y = holiday(7,4)
v =
logical
0
y =
logical
0
Best regards
Stephan

Arrah Calvin
Arrah Calvin 2018 年 7 月 30 日
編集済み: Stephen23 2018 年 7 月 30 日
Here is my take on the problem. I've tested it, and it works. I don't know why your function doesn't work while it looks like it should.
function [v] = holiday(month,day)
a=[1,1];
b=[7,4];
c=[12,25];
d=[12,31];
A = [month,day];
if A == a
v=true;
elseif A == b
v=true;
elseif A == c
v=true;
elseif A == d
v=true;
else
v=false;
end

Duddela Sai Prashanth
Duddela Sai Prashanth 2018 年 9 月 23 日
%Simplest one - Tested
function value = holiday(month,day)
if month == 1 && day == 1
value = true;
elseif month == 7 && day == 4
value = true;
elseif month == 12 && (day == 25 || day == 31)
value = true;
else
value = false;
end

Akshatha Gangappa
Akshatha Gangappa 2018 年 10 月 17 日
function [v] = holiday(m,d) if (( m==1 && d ==1) (m==7 && d ==4) (m==12 && d ==25)||(m ==12 && d== 31)) v = true; else v = false; end end

muhammad usman
muhammad usman 2020 年 4 月 5 日
function H = holiday(month,day);
if (month == 1 && day == 1) || (month == 7 && day ==4) || (month == 12 && day == 25) || (month == 12 && day == 31);
H = true;
else fprintf(' go to work\n '); H = false;
end

カテゴリ

Help Center および File ExchangeCalendar についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by