Please note that arrayfun isn't a vectorized solution as most certainly it uses loops behind-the-scenes and seems like mat2cell is using for loops inside its source code, so please do keep all these issues in mind. This seems to perform much better than with mat2cell in terms of performance. Now, another approach if you would like to preserve the cell format would be with arrayfun, assuming each cell of M to be a 4D numeric array - M = num_array(:,:,:,:,x),1:N,'Uniform',0) Some quick tests show that mat2cell would prove to be the bottleneck, so if you don't mind indexing into the intermediate numeric array variable num_array and use it's last dimension for an equivalent indexing into M, then this approach could be useful. M = squeeze(mat2cell(num_array,size_num_arr2c,ones(1,num_cells))) %// thus obtained numeric array from its first to the second last dimension %// Save the numeric array as a cell array with each block from Num_array = permute(reshape(num_array,size_num_arr),perm_dim) %// for indexing data from different cells ends up as the final dimension The array produced has the same values as A but the order of the subscripts needed to access any particular element are rearranged as specified by ORDER. Matrix P has the same data type as v, and it has n rows and n columns. Each row of P contains a different permutation of the n elements in v. %// Reshape and permute the numeric array such that the index to be used The matlab code uses the method permute: B PERMUTE (A,ORDER) rearranges the dimensions of A so that they are in the order specified by the vector ORDER. P perms (v) returns a matrix containing all permutations of the elements of vector v in reverse lexicographic order. %// Store data from input M into a vertically concatenated numeric array %// Dimensions array for permuting with the numeric array holding all data %// input cell array with the second dimension representing the index of %// Get size of the numeric array that will hold all of the data from the This seems to work - num_cells = numel(M) %// Number of cells in input cell array
0 Comments
Leave a Reply. |