フィルターのクリア

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 Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by