![]() 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 %// Reshape and permute the numeric array such that the index to be used %// Store data from input M into a vertically concatenated numeric array However, if one tests the memory usage of a multidimensional permutation, it's the same as the variable used. %// Dimensions array for permuting with the numeric array holding all data Why does MATLAB's permute not need extra memory The permutation operation needs to output a different matrix to the output, it's not like reshape, where the data is not modified, permute does modify the 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. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |