Two questions:
1) I’ve found a piece of code that says something like cellArr{x}{y}{3,8} = 1.0;, I was wondering what the {3,8} means. The program connections various nodes in a collections of connected graphs together. Here we would say that “in the set of graphs x, the graph y’s connection from 3 to 8 has a vertex label of 1.0”. Still, in general what does the syntax {3,8} mean in MatLab?
2) This probably isn’t the place for this question but should I really be using cell arrays if I know I’m always going to be having vertex values i.e. decimals/floats. Would a matrix be better because I know I’m only going to have a single data type?
Thank you :).
Cell arrays can have multiple dimensions, and thus they can be indexed with multiple subscripts like any other multidimensional array. The syntax
{3,8}is indexing a (presumably) 2-D cell array, getting the contents of the cell in the third row and eighth column.There are two main reasons to use cell arrays: storing data of different types or storing data of different sizes. Assuming
xandyare scalar indices in your example, thencellArris a cell array with the cell indexed byxcontaining another cell array, whose cell indexed byycontains a 2-D cell array which stores your vertex labels.Now, if your vertex labels are all the same data type and are all just single non-empty (i.e. not
[]) values, then the 2-D cell array at the lowest level could be turned into a 2-D numeric array, and your indexing will look like this:The question now becomes how to handle the two enclosing sets of cell arrays indexed by
xandy. If every cell that can be indexed byycontains 2-D numeric arrays all of the same size and type, then that cell array could be turned into a 3-D numeric array that could be indexed like so:Finally, if every cell that can be indexed by
xcontains 3-D numeric arrays that are again all of the same size and type, thencellArrcould be turned into a 4-D numeric array that could be indexed like so:You could change the order of the subscripts (i.e. the dimensions of
numArr) to your liking, but I putxandyat the end so that if you were to index a subarray of vertex labels likenumArr(:,:,y,x)it will return it as a 2-D array. If you had the indices ordered such that you would index a subarray of vertex labels likenumArr(x,y,:,:), it will return the result as a 4-D array with ones for the two leading singleton dimensions (which you would have to remove using functions like SQUEEZE).