How can I create a heterogenous array using 'arrayfun' in MATLAB R2024b?
조회 수: 5 (최근 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!