How can I access all values of type 'function_handle' from a dictionary in MATLAB R2022b?
조회 수: 29 (최근 30일)
이전 댓글 표시
MathWorks Support Team
2024년 10월 14일
답변: MathWorks Support Team
2024년 10월 16일
이 질문에 Walter Roberson
님이 플래그를 지정함
I have defined a dictionary with they keys as strings and values as function handles as follows:
>> dict = configureDictionary("string","function_handle");
>> dict("a") = @(a) a;
>> dict("b") = @(b) b;
When I try to access all values in the dictionary, it throws the following error:
>> dictVals = dict.values;
Unable to combine entry parts.
How can I retrieve all values of the dictionary?
채택된 답변
MathWorks Support Team
2024년 10월 14일
MATLAB does not support grouping function handles as a traditional matrix or array but provides the option of clubbing multiple function handles together as a cell array. More information on this can be found under the “Arrays of Function Handles” subsection in the documentation.
Additionally, when looking at the code provided, a possible workaround is to retrieve the dictionary values as a cell array. Please consider the following code:
>> dict = configureDictionary(“string”, “function_handle”);
>> dict(“a”) = @(a) a;
>> dict(“b”) = @(b) b;
>> dictVals = dict.values(“cell”); % This should return a cell array of function handles.
For further information on how to refer to dictionary values as a cell array, please refer to the following documentation:
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Dictionaries에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!