Help needed with the program
이전 댓글 표시
function [x] = holiday( month, day )
M = [1,2,3,4,5,6,7,8,9,10,11,12];
D = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31];
if nargin < 1
error('The input must be a positive integer');
end
if ~isscalar(month) || month <1 || month ~= fix(month)
error ('The input "Month" must be positive integer');
elseif ~isscalar(day) || day <1 || day ~= fix(day)
error ('The input "Day" must be positive integer');
end
*if(M == 1 && D ==1) || (M == 7 && D == 4) || (M == 12) && D == 25) || (M == 12 && D == 31)*
x = true;
else
x = false;
end
end
Matlab says that The text that i have made bold is wrong. Error occurs:,saying: Unexpected bracket or parenthesis.
Can anyone please clarify this for me?
댓글 수: 5
KSSV
2018년 8월 8일
What is that you are trying? Your code is a mess.
Yash Sunil Runwal
2018년 8월 8일
KALYAN ACHARJYA
2018년 8월 8일
Which line the error it shows?
Yash Sunil Runwal
2018년 8월 8일
KALYAN ACHARJYA
2018년 8월 8일
I have edited the answer, pls check and confirm. I have removed all non-mandatory lines, you can add them after successfully execute the code.
채택된 답변
추가 답변 (1개)
KALYAN ACHARJYA
2018년 8월 8일
편집: KALYAN ACHARJYA
2018년 8월 8일
function x=holiday(m,d)
i={1,2,3,4,5,6,7,8,9,10,11,12};
j={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31};
if(i{m}==1 && j{d}==1) || (i{m}==7 && j{d}==4) || (i{m}==12 && j{d}==25) || (i{m}==12 && j{d}==31)
x='true';
else
x='false';
end
end
댓글 수: 6
KSSV
2018년 8월 8일
Note that, in the function M, D are vectors......equating a vector to scalar wont be of use.
Yash Sunil Runwal
2018년 8월 8일
Yash Sunil Runwal
2018년 8월 8일
KALYAN ACHARJYA
2018년 8월 8일
Thank you @KSSV Sir
KALYAN ACHARJYA
2018년 8월 8일
@ Yash Sunil I have tested the code in small way, you can do the same

for more data.
Yash Sunil Runwal
2018년 8월 8일
카테고리
도움말 센터 및 File Exchange에서 Calendar에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!