Extrapolation/error handling

조회 수: 1 (최근 30일)
Rava Sash
Rava Sash 2018년 4월 24일
댓글: Stephen23 2018년 4월 25일
I'm trying to prevent extrapolation, the input speed (v) can't be lower than 2 or higher than 200. I'm trying to use if/else but I'm being told by a "test-programme" that "Function does not result in error when input results in extrapolation". What am I doing wrong?
My code:
function c = consumption(v)
load roadster.mat;
x = 2:2:200;
y = consumption_Whpkm;
xx=2:200;
pp=spline(x,y);
c = ppval(pp, v);
if v<2 | v>200
error ('Too fast/slow')
else
contine
end
end
  댓글 수: 1
John D'Errico
John D'Errico 2018년 4월 25일
편집: John D'Errico 2018년 4월 25일
Don't answer your own question, and just with a comment. Use a comment. Or edit your question.
Moved an answer by Rava into a comment.
"Should I use try/catch? If so, how would that work? I'm very new to programming and Matlab, any help is appriciated."

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

채택된 답변

Stephen23
Stephen23 2018년 4월 25일
I am guessing that v is non-scalar, in which case you will need to use any:
if any(v<2 | v>200)
  댓글 수: 2
John D'Errico
John D'Errico 2018년 4월 25일
I wonder if the else branch of that if may fail, when the "contine" function is executed. Is that a miss-spelling of "continue"?
Stephen23
Stephen23 2018년 4월 25일
I quite like the sound of "contine", whatever it may do. It sounds like a french holiday.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by