Best data structure to use?
조회 수: 4 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
답변 (2개)
Image Analyst
2014년 1월 16일
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!