Why does MATLAB 6.5 (R13) report the wrong SIZE and LENGTH result on a matrix returned by RESHAPE?

1 view (last 30 days)
Why does MATLAB 6.5 (R13) report the wrong SIZE and LENGTH result on a matrix returned by RESHAPE?
This problem only occurs when the code is inside a script or function. The following code will reproduce the problem:
a=[1 1 1 1 1 1 1 1 1 1 1 1]
size(a)
length(a)
b=reshape(a,[2,2,3])
size(b)
length(b)
Notice how the last dimension is left off the size of "b", and the length does not recognize the 3rd dimension, either.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
This bug has been fixed for Release 14 (R14). For previous releases, please read below for any possible workarounds:
This problem has been fixed in MATLAB 6.5.1 (R13SP1). If you are using a previous version, read the following:
This is a bug in MATLAB 6.5 (R13) . The source of the bug is inside the MATLAB JIT Accelerator.
There are two workarounds for this issue. First, you can add a DRAWNOW command following the call to RESHAPE. For example:
a=[1 1 1 1 1 1 1 1 1 1 1 1]
size(a)
length(a)
b=reshape(a,[2,2,3])
drawnow
size(b)
length(b)
If the first workaround does not work, you can try the following:
feature accel off
a=[1 1 1 1 1 1 1 1 1 1 1 1]
size(a)
length(a)
b=reshape(a,[2,2,3])
size(b)
length(b)
feature accel on
This will execute the code with the JIT accelerator turned off and turn the accelerator back on after the code is finished executing. Note that if the code is interrupted before the "feature accel on" line is executed, the accelerator will remain disabled for the remainder of the session unless otherwise turned on.

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!