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
    7 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
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.
0 Commenti
Risposte (5)
  Stephan
      
      
 il 6 Giu 2018
        
      Modificato: Stephan
      
      
 il 6 Giu 2018
  
      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
 il 30 Lug 2018
        
      Modificato: Stephen23
      
      
 il 30 Lug 2018
  
      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
0 Commenti
  Duddela Sai Prashanth
 il 23 Set 2018
        %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
0 Commenti
  Akshatha Gangappa
 il 17 Ott 2018
        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
0 Commenti
  muhammad usman
 il 5 Apr 2020
        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
0 Commenti
Vedere anche
Categorie
				Scopri di più su Calendar in Help Center e File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!






