Query data from 1xn struct

1 visualización (últimos 30 días)
Le Vu Bao
Le Vu Bao el 14 de Jul. de 2019
Editada: Le Vu Bao el 15 de Jul. de 2019
Hi, I have a 1x3 struct just like below:
% Q(1)
Q(1).name='carrot';
Q(1).price=200;
Q(1).number=1000;
%Q(2)
Q(2).name='banana';
Q(2).price=200;
Q(2).number=2000;
%Q(3)
Q(3).name='apple';
Q(3).price=900;
Q(3).number=200;
How can I quickly query "price" of "banana" or "number" of "apple"?
Is there any shorcut beside manually gathering name to string array (Q.name returns scattering outputs)

Respuesta aceptada

Rik
Rik el 14 de Jul. de 2019
The table data type is probably a better choice for your usage. Then you can also easily index.
  2 comentarios
madhan ravi
madhan ravi el 14 de Jul. de 2019
True using struct2table()
Le Vu Bao
Le Vu Bao el 15 de Jul. de 2019
Editada: Le Vu Bao el 15 de Jul. de 2019
oh,how silly I am. Thank you.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Structures en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by