image thumbnail

reshape0, reshaping with padding or truncating

version 1.0.0.0 (4.99 KB) by James Tursa
A c-mex routine for reshaping with padding or truncating

1.2K Downloads

Updated 11 Feb 2008

No License

Reshapes an array like the MATLAB intrinsic reshape function. But reshape0 does not require that the total number of elements must remain the same. If the new array is larger, then it will be zero or blank padded. If the new array is smaller, then it will be a truncated version of the original. char arrays are padded with blanks, cell arrays are padded with empty double arrays, logical arrays are padded with false (zeros), and all other numeric arrays are padded with 0's. Structures cannot be padded or truncated (this feature is not yet implemented for the struct class ... maybe in a future version).

reshape0 is not as efficient as reshape when there is no truncating or padding involved because reshape0 will generally copy data whereas reshape will do a lazy copy.

Building (one-time only):

>> mex -setup
(then follow instructions to select a C / C++ compiler of your choice)
>> mex reshape0.c

That's it! Now you are ready to use reshape0.

In the unlikely case you get this error message:

bit16 define symbol is not a 16-bit integer

You will need to change the definition of the bit16 symbol in the reshape0.c file. You need to ensure that this is a 16-bit integer type for your system so that the MATLAB char class (which is 16 bits) will work properly. You might have to change the word "short" to something like int16_t or uint16_t to get it to work. Contact me and I will help.

Cite As

James Tursa (2021). reshape0, reshaping with padding or truncating (https://www.mathworks.com/matlabcentral/fileexchange/18684-reshape0-reshaping-with-padding-or-truncating), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2006a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!