MATLAB 2023a: How to assign multiple values(keys?) to one key using dictionaries?
Mostrar comentarios más antiguos
I have a dataset consisting of "devices" (samples) that I have tested. I'd like to create a large dictionary that will create keys based on all of the sample's names, and then subsequently create more keys inside of that sample name corresponding to the "JV Parameters" and "Device Results". Inside of the "JVParameters" would be the voltage and current that was measured (these are both lists), and inside "Results" I'd get the device PCE, Jsc, Voc, and FF.
How can I assign multiple keys to this one sample to hold all of this information? Say if I want to see the performance of a device I can search up dict({D101_1}{Results}{PCE}), or if i want the voltages it was tested at, I could use d({D101_1}{JVParams}{Voltage}).
In Python I could call these keys and assign multiple keys in a dictionary by using [D101_1][Results][PCE] but I'm not sure how to do this in matlab 2023a. Please let me know if this makes any sense or not. Image attached.

2 comentarios
Vilém Frynta
el 11 de Abr. de 2023
I would love to help, but first I would need to understand something more before I evaluate the best options.
How many devices do you have?
How many JVParams does each device have? Just one? And does each device have just one Results?
Daniel Morales
el 11 de Abr. de 2023
Respuesta aceptada
Más respuestas (1)
Walter Roberson
el 11 de Abr. de 2023
Editada: Walter Roberson
el 12 de Abr. de 2023
You can create a dictionary which takes scalar keys, for which the associated values are (distinct) dictionaries.
You can create a dictionary which takes scalar keys, and the associated values are cell arrays. But you have to be a bit careful with that:
d = dictionary;
d("parts") = {{'transmission', 'gearshaft'}}
Notice I had to enclose the cell array inside a different cell array. That is because assignment into a dictionary permits multiple assigment, NAME(VECTOR_OF_KEYS) = CELL_OF_VALUES and key VECTOR_OF_KEYS(K) is assigned value CELL_OF_VALUES{K}
1 comentario
Daniel Morales
el 12 de Abr. de 2023
Categorías
Más información sobre Instrument Control Toolbox en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!