Borrar filtros
Borrar filtros

Dictionary with key-value pair of string ---> string array?

36 visualizaciones (últimos 30 días)
the cyclist
the cyclist el 6 de Abr. de 2024 a las 22:08
Editada: the cyclist el 7 de Abr. de 2024 a las 0:46
Using the older containers.Map object, I can map a string to a string array:
keySet = ["Jan";"Feb";"Mar"];
valueSet = {["New Year","MLK"]; ["Valentine's","Presidents'"];[]};
M = containers.Map(keySet,valueSet);
M("Jan")
ans = 1x2 string array
"New Year" "MLK"
I have not found a way to make a similar mapping via the newer dictionary object (even though the documentation states that a dictionary is preferred "because it supports more data types as keys and values and provides better performance").
Maybe I'm overlooking something. Any suggestions are appreciated.

Respuesta aceptada

Paul
Paul el 6 de Abr. de 2024 a las 22:59
Hi cyclist,
Do you mean mapping to the string array contained inside the cell?
keySet = ["Jan";"Feb";"Mar"];
valueSet = {["New Year","MLK"]; ["Valentine's","Presidents'"];[]};
d = dictionary(keySet,valueSet)
d = dictionary (string --> cell) with 3 entries: "Jan" --> {["New Year" "MLK"]} "Feb" --> {["Valentine's" "Presidents'"]} "Mar" --> {0x0 double}
d("Jan")
ans = 1x1 cell array
{["New Year" "MLK"]}
d{"Jan"}
ans = 1x2 string array
"New Year" "MLK"
  1 comentario
the cyclist
the cyclist el 7 de Abr. de 2024 a las 0:46
Editada: the cyclist el 7 de Abr. de 2024 a las 0:46
I could have sworn I tried that exact syntax! sigh
Thanks for the answer.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Productos


Versión

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by