Best data structure to use?

3 views (last 30 days)
Mike
Mike on 16 Jan 2014
Answered: Image Analyst on 16 Jan 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.

Answers (2)

Suneesh
Suneesh on 16 Jan 2014

Image Analyst
Image Analyst on 16 Jan 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.

Tags

Community Treasure Hunt

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

Start Hunting!