필터 지우기
필터 지우기

How to use "error " in code in function

조회 수: 4 (최근 30일)
aldo
aldo 2023년 8월 23일
댓글: aldo 2023년 8월 23일
I have a code that works perfectly..
i try to use error in a condition:(it's use in a funcion called in app designer)
if true
error('Error. \n groupRank contiene ripetizione elementi'); %%check per scurezza..per come ho impostato la logica del rank in groupRank ci deve essere 1 solo sistema nei gruppi di rank!
return;
end
and i receive this error:
Error using Calcola_FiltroRaking_Struct
Error. \n groupRank contiene ripetizione elementi
Error in Predator_Filtri_Preset_Struct (line 96)
filtroRanking=Calcola_FiltroRaking_Struct(Sis,Eq,Preset,contract);
Error in PredatorBEGIN_AppDesign_Struct (line 94)
Eq=Predator_Filtri_Preset_Struct(Sis,Eq,Preset); % MI CREA IL Eq.Filtri.filtro_Finale dalla curva base..(usa il filtro_oos PER IL RANKING!!)
Error in Predy/AvvioPredatorButtonPushed (line 583)
[app.eq,app.sis]=PredatorBEGIN_AppDesign_Struct(app.setting,app.preset);
i dont understand the other error (line 96..line 94) what kind of error is
I don't receive ani information about it
I can't to post code...
the code is very elaborate and they are functions called in the app designer
I would like when the error occurs to exit the "Main" program completely but I see that "return" does not do this

답변 (1개)

Florian Bidaud
Florian Bidaud 2023년 8월 23일
편집: Florian Bidaud 2023년 8월 23일
It is just telling you where the error occurs in each subfunction.
You can't have a return after the 'error' because error WILL error and then stop the code.
Do you really need the error ?
You could just remove it so it would leave the function with the return,
And then throw an error.
For example:
% your code
output = yourFunction(inputs)
if strcmp(output,'error')
error('Error. \n groupRank contiene ripetizione elementi')
end
function output = yourFunction(inputs)
% your function code
if true
output = 'error';
return;
end
end
  댓글 수: 1
aldo
aldo 2023년 8월 23일
in case of check the condition "X" i want to use from main code

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

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by