How can I access all values of type 'function_handle' from a dictionary in MATLAB R2022b?
29 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
MathWorks Support Team
el 14 de Oct. de 2024
Respondida: MathWorks Support Team
el 16 de Oct. de 2024
Walter Roberson
ha marcado con alerta este/a pregunta
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?
Respuesta aceptada
MathWorks Support Team
el 14 de Oct. de 2024
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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Dictionaries en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!