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
Cite As
Noam Katz (2026). reindex (https://www.mathworks.com/matlabcentral/fileexchange/17656-reindex), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
| Version | Published | Release Notes | |
|---|---|---|---|
| 1.0.0.0 | Address review, clarify use of function |
