Best data structure to use?

4 visualizaciones (últimos 30 días)
Mike
Mike el 16 de En. de 2014
Respondida: Image Analyst el 16 de En. de 2014
Hello All,
I have some experience with programming but I'm very new to Matlab.
Could anyone recommend the best data structure to use for my requirements?
I basically want to represent an agent which has the following attributes: identifier (simple string will do), x position and y position. I will have up to 10 of these. I'll need to update the positions on a regular basis.
Many Thanks in advance.

Respuestas (2)

Suneesh
Suneesh el 16 de En. de 2014

Image Analyst
Image Analyst el 16 de En. de 2014
I'd probably use a structure array :
agentNumber = 8; % Whichever...
agent(agentNumber).id = 'whatever';
agent(agentNumber).x = 42;
agent(agentNumber).y = 123;
It may be faster to use a 2D array for x and y and the "agentnumber" is the row, and a cell array or character array for the strings. For only 10 agents, speed is not an issue. If you have millions of them then you may want to experiment with different ways of doing it.

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by