different outcome cellfun(@isempty,..) vs cellfun('isempty',...)
7 ビュー (過去 30 日間)
古いコメントを表示
I have multiple tables stored in a cellarray. However some cells become empty [ ] after the removal of missing values.
My goal is to find out which cells become empty after this removal of ... .
I tried to do this with cellfun(@isempty,mycell) which does the job.
Further I tried to do this with cellfun('isempty',mycell) (according to what I've read this should be faster).
However the output is not the same (the last one returns a logical vector with all logical zero's).
I've checked the documentation but could not figure out why the outcomes differ.
0 件のコメント
採用された回答
Rik
2021 年 3 月 11 日
The reason is partly documented:
"If you specify a function name rather than a function handle cellfun does not call any overloaded versions of the function."
It turns out that the table data type has an overloaded isempty method. As far as I could find this is not documented.
The only solution is as Steven mentions: if you want to make sure you have the expected output, use the non-legacy syntax. If you need to add something that checks the classes of the cell elements all speedup is lost, so you can only use this for cell that you have complete control over.
0 件のコメント
その他の回答 (1 件)
Steven Lord
2021 年 3 月 11 日
I recommend you avoid using the 'isempty' syntax in new code. It is present for backwards compatibility with (very) old code and its behavior does differ from the function handle syntax as stated in the description of the func input argument on the documentation page for the cellfun function.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!