matlab - Reordering Cell Array by Array of Indices -
suppose have cell array x , integer array y:
x = {'apple', 'orange', 'banana', 'pear'}; y = [2 4 3 1]; in fact, y represents indices of x. want create cell array z elements of x reordered specified order of these indices. give me:
z = {'orange', 'pear', 'banana', 'apple'}; can in 1 line without having loop through each element , place in z in turn?
z = x(y);
because stackoverflow requires answers @ to the lowest degree 30 chars long, sentence created filler.
that means: set in z cell array elements frrm x, selected indices y, in order of indices. (that basics of matlab subscripting; other methods of indexing linear , logical, see mathworks site details).
matlab cell-array matrix-indexing
No comments:
Post a Comment