How to use error handler for arrayfun?

10 ビュー (過去 30 日間)
Struggling in MATLAB
Struggling in MATLAB 2022 年 12 月 4 日
I am trying to apply a function to an big array. The output is a logical output. I checked that this arrayfunction is working for me.
% apply function to 'input_data.id' array
logicalOutput = arrayfun(@(id) passingCentralZone(id), input_data.id(1:10));
This function will fail for a few entry where we have bad/corrupt data in the database. I want to use an error handler. Ideally I want to have nan value or logical 0 for those bad data. I looked at the documentation, but did not understand much. Can anyone please help with this?
  2 件のコメント
Stephen23
Stephen23 2022 年 12 月 4 日
logicalOutput = arrayfun(@passingCentralZone, input_data.id(1:10), 'ErrorHandler',@(varargin) false);
% simpler fun handle: ^^^^^^^^^^^^^^^^^^^
% error handling function ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Struggling in MATLAB
Struggling in MATLAB 2022 年 12 月 4 日
Thanks for your comment. I am using this simpler function handle.

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2022 年 12 月 4 日
logicalOutput = arrayfun(@(id) passingCentralZone(id), input_data.id(1:10), 'ErrorHandler', @(s,varargin) false());
  1 件のコメント
Struggling in MATLAB
Struggling in MATLAB 2022 年 12 月 4 日
Thank you very much!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAutomotive についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by