필터 지우기
필터 지우기

why do i get this untitled error ?

조회 수: 35 (최근 30일)
omar khater
omar khater 2016년 9월 8일
댓글: Thorsten 2016년 9월 8일
this is the function code
function dd=day_diff(month1, day1, month2, day2)
if((month1 >12) ||( month2>12) || (day1 >31) ||(day2>31)||(month1==2&&day1>28))
error('1');
end
m=[31 28 31 30 31 30 31 31 30 31 30 31];
if (month1>1)
d1=sum(m(1:month1-1))+day1;
else d1=day1;
end
if (month2>1)
d2=sum(m(1:month2-1))+day2;
else d2=day2;
end
dd=abs(d1-d2);
when i run the code and fail in the conditon (month1==2&&day1>28)
i get this response
>> day_diff(2,29,1,30)
Error using day_diff (line 4)
1
the Matlab show the error message but give me untitled error !
  댓글 수: 1
Thorsten
Thorsten 2016년 9월 8일
Note that you do not generate an error if if the months has only 30 days, but you set day to 31.

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

답변 (1개)

Star Strider
Star Strider 2016년 9월 8일
You are creating that in your function! Calling error displays the error message and stops execution. See the documentation (link) for details.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by