Matlab7 question
I want to have a 2D matrix which each cell of the matrix is a linked list.
Is this possible in mathlab?
I don't think you could use it without writing a little custom script, but I don't see why a matrix couldn't hold memory addresses instead of values. I just wouldn't expect the standard operations to handle it gracefully.
Then again, maybe you could make it work.
Good luck!
Then again, maybe you could make it work.
Good luck!
The closest thing to that using what MATLAB provides is a cell matrix of vectors. There are no linked lists in MATLAB, and writing your own in MATLAB script is nothing I recomend. It's going to be really messy, as MATLAB doesn't have anything similar to pointers or references; only values.
If you really, REALLY, need a linked list structure over a vector structure in MATLAB, I strongly suggest you write one yourself in C or C++ and compile into a MEX-file.
The cell matrix is created and accessed like this.
A is now a 2 by 3 cell matrix. Initially all elements are empty vectors.
Use {} to access cells, not () as with arrays, and each cell is an independent entity. Each cell can contain different types (strings, vectors, nested cell matrices, aything), and of different size aswell.
If you really, REALLY, need a linked list structure over a vector structure in MATLAB, I strongly suggest you write one yourself in C or C++ and compile into a MEX-file.
The cell matrix is created and accessed like this.
>> A=cell(2, 3)A = [] [] [] [] [] []
A is now a 2 by 3 cell matrix. Initially all elements are empty vectors.
>> A{2,2} = [1 2 3 4]A = [] [] [] [] [1x4 double] []
Use {} to access cells, not () as with arrays, and each cell is an independent entity. Each cell can contain different types (strings, vectors, nested cell matrices, aything), and of different size aswell.
There are some common extensions that add linked list functionality to matlab.
For instance: http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=212&objectType=file
For instance: http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=212&objectType=file
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement