Code covered by the BSD License  

Highlights from
Digital Karma: State Graphing

image thumbnail
from Digital Karma: State Graphing by Aman Siddiqi
Evolutionary Simulation, Interaction Graph

matrixnumber=coordinate2element_num(matrix,row, col, plane);
function matrixnumber=coordinate2element_num(matrix,row, col, plane);
% coordinate2element_num(matrix,row, col, plane);
% Enter the matrix, then the row & column (layer is optional)
% I can adapt the sub2ind code if I need this for more than 3 dimensions
% I didn't now because this looks faster than their N-dimension version

if nargin==3; plane=1; end;
[matrixrows, matrixcols, matrixplanes]=size(matrix);

if row<=matrixrows & col<=matrixcols & plane<=matrixplanes
    matrixnumber=((matrixrows*(col-1))+row)+((plane-1)*matrixrows*matrixcols);
else;
    matrixnumber=['Coordinates exceend matrix dimensions'];
end;

Contact us at files@mathworks.com