![]() ![]() 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. In general, the ith dimension of the output array is the dimension dimorder (i) from the input array. For example, permute (A, 2 1) switches the row and column dimensions of a matrix A. M = squeeze(mat2cell(num_array,size_num_arr2c,ones(1,num_cells))) B permute (A,dimorder) rearranges the dimensions of an array in the order specified by the vector dimorder. The input and output dimensions of the model array are not counted as array dimensions for this operation. The function performs transposition implicitly, and transposes directly only if necessary. Description example newarray permute (sysarray,order) rearranges the array dimensions of a model array so that the dimensions are in the specified order. If the input dlarray is formatted, then the labels of both dimensions must be the same. Size_num_arr2c = num2cell(size_num_arr2(1:end-1)) The function performs permutations implicitly, and permutes directly only if necessary for other operations. ![]() If is a vector of integers, then each element of indicates the shift amount in the. If is an integer, then shifts along the first dimension of whose size does not equal 1. %// thus obtained numeric array from its first to the second last dimension Y circshift (A,K) Y circshift (A,K,dim) Y circshift ( circularly shifts the elements in array positions. The function A, I npermutek (v,k) returns both the matrix and indeces. ![]() of k elements from the vector v without repetitions. This function A npermutek (v,k) returns all the possible permutations. %// Save the numeric array as a cell array with each block from NPERMUTEK - permutations without repetitions. Num_array = permute(reshape(num_array,size_num_arr),perm_dim) 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. %// for indexing data from different cells ends up as the final dimension P perms(v) returns a matrix containing all permutations of the elements of vector v in reverse lexicographic order. %// Reshape and permute the numeric array such that the index to be used %// 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. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |