reindex(x,y) adds dimensions without the confusion of reshape. It makes x look like y. For example:
x = ones([1 5]);
y = ones([6 5 9]);
z = y + x; %this fails
z = y + reindex(x,y); %but this does not
Works for arbitrary dimensions, as long as all non-singleton dimensions of x are also dimension of y.
reindex is more general than bsxfun (though maybe slower), because it can do repmat and permute without much thought from user:
x = zeros([5 9]);
y = ones([3 5 1 9 2]);
z = bsxfun(@minus,y,x)); %fails because dimensions don't match
z = y-reindex(x,y); %works, z has dimension of y
Noam Katz (2021). reindex (https://www.mathworks.com/matlabcentral/fileexchange/17656-reindex), MATLAB Central File Exchange. Retrieved .
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!