Representing a tree in Matlab?
October 6, 2008 9:16 PM   Subscribe

What is a good way to represent an N-ary tree in Matlab?

I am working on a classic AI problem. (Minimax with Alpha-Beta pruning). I need to represent all possible game states in a tree. How would you go about expanding the tree and representing it in some data structure?
posted by fake to Computers & Internet (9 answers total) 1 user marked this as a favorite
Simple. Each node has an list of children, which are (possibly pointers to) node type. List is a linked list or vector (resizable array) type.
posted by orthogonality at 9:45 PM on October 6, 2008

orthogonality: Is that matlab-specific advice?

Matlab has things like treeplot where you make a matrix with each cell representing a tree node, and containing the matrix index of that node's parent. There are also toolboxes available; and you can make nested structs.

That said, a big benefit of Matlab is simple code and helpful libraries; if you put your data in a weird format you begin to lose those benefits.
posted by Mike1024 at 2:38 AM on October 7, 2008

Response by poster: Mike1024 -- thanks. The treeplot matrix format is pretty close to what I am looking for. The toolbox you linked doesn't work on my system (I'd found it before), and I've had some issues with indexing into nested structs (my first guess at a good way to build up a tree). However, that speaks more to my (lack of) programming skills than any problem with structs.

I'm still interested in more ideas from anyone with experience here, but I should be able to do the job with the simple treeplot format.
posted by fake at 5:15 AM on October 7, 2008

This might help?
posted by dmd at 7:17 AM on October 7, 2008

Response by poster: thanks dmd, however, as I said in my previous comment, i couldn't get that toolbox to work. i found it and the help struct page and searched the hell out of google before i came here.
posted by fake at 8:12 AM on October 7, 2008

Best answer: You can pull Java code into MATLAB - see this guide. Java is popular for intro computer science courses, and it has several programming constructs that Matlab is missing, so I'd imagine you could find a tree implementation in Java somewhere online.
posted by Mike1024 at 12:52 AM on October 8, 2008

Response by poster: Thanks, Mike1024. That is exactly what I was looking for.
posted by fake at 9:02 AM on October 12, 2008

Best answer: fake, my research involves as one of its more laborious chores haranguing tree structures around back and forth between MATLAB and C++ mex files. I'm happy to help you if you've got further questions about this stuff.
posted by onalark at 7:33 PM on November 6, 2008

Response by poster: Onalark, I ended up solving this problem but I may take you up on your offer. Thank you so much.
posted by fake at 9:16 AM on November 22, 2008

« Older Soundtrack to Strut To   |   Big girls want cute clothes too. Newer »
This thread is closed to new comments.