How can I create a heterogenous array using 'arrayfun' in MATLAB R2024b?
1 回表示 (過去 30 日間)
古いコメントを表示
MathWorks Support Team
2025 年 4 月 23 日
回答済み: MathWorks Support Team
2025 年 4 月 24 日
When I use 'arrayfun' to create a heterogenous array in MATLAB R2024b, it fails with an error:
Mismatch in type of outputs
Why does this error occur, and how can I create a heterogenous array without any issues?
採用された回答
MathWorks Support Team
2025 年 4 月 23 日
In MATLAB R2024b, 'arrayfun' cannot directly create a heterogenous array. However, you can accomplish this using 'horzcat' or an equivalent function.
First, when using 'arrayfun', specify the 'UniformOutput' name-value argument as 'false'. This will return a cell array, which can then be concatenated into a heterogenous array.
For example:
A = arrayfun(@(x) foo(x), X, 'UniformOutput', false);
A = horzcat(A{:});
The functions 'cat', 'horzcat', and 'vertcat' support creating heterogenous arrays of classes which derive from 'matlab.mixin.Heterogenous'. The documentation section A Class Hierarchy for Heterogeneous Arrays describes this in further detail.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!