Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Bug in mat2cell?

Subject: Bug in mat2cell?

From: Bruno Luong

Date: 25 Nov, 2007 10:48:03

Message: 1 of 6

Hello

X=rand(2,2,2);
C=mat2cell(X,2,[1 1],[1 1]);

The last instruction produces the following error message,
which I think is a bug.

??? Index exceeds matrix dimensions.

Error in ==> mat2cell at 227
        c{cind} = x(tref{:});

My MATLAB version is 7.3.0.267 (R2006b).

Comments?

Bruno

Subject: Bug in mat2cell?

From: Bruno Luong

Date: 25 Nov, 2007 11:30:51

Message: 2 of 6

See above

Subject: Bug in mat2cell?

From: Bruno Luong

Date: 25 Nov, 2007 12:16:14

Message: 3 of 6

I look at the Mathworks's mat2cell code, and at the line
#198, the array ref is updated under certain condition:

...
if (inc~=1) && ~(cellsize(1)==1)
    [ref{1:inc-1}] = deal(refstart{1:inc-1});
    refstatic(1:inc-1) = 0;
end
...

The condition ~(cellsize(1)==1) seems to cause the Bug. If I
remove it from the test, as following:

...
if (inc~=1)
    [ref{1:inc-1}] = deal(refstart{1:inc-1});
    refstatic(1:inc-1) = 0;
end
...

it works. I'm not sure what is the test on cellsize(1) is
for, and I'm not sure I would introduce a mess in mat2cell
function by removing it. Hope someone at mathworks could
answer the question.

Bruno

Subject: Bug in mat2cell?

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 25 Nov, 2007 20:38:49

Message: 4 of 6

In article <fibjt3$64b$1@fred.mathworks.com>,
Bruno Luong <brunoluong@yahoo.com> wrote:

>X=rand(2,2,2);
>C=mat2cell(X,2,[1 1],[1 1]);

>The last instruction produces the following error message,
>which I think is a bug.

>??? Index exceeds matrix dimensions.

>My MATLAB version is 7.3.0.267 (R2006b).

No error is produced in R2007a.
--
   "Okay, buzzwords only. Two syllables, tops." -- Laurie Anderson

Subject: Bug in mat2cell?

From: Bruno Luong

Date: 25 Nov, 2007 22:11:21

Message: 5 of 6

roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in message
>
> No error is produced in R2007a.

Thanks!

Subject: Bug in mat2cell?

From: Bruno Luong

Date: 26 Nov, 2007 09:04:29

Message: 6 of 6

"Bruno Luong" <brunoluong@yahoo.com> wrote in message
<fibp2d$sff$1@fred.mathworks.com>...
> I look at the Mathworks's mat2cell code, and at the line
> #198, the array ref is updated under certain condition:
>
> ...
> if (inc~=1) && ~(cellsize(1)==1)
> [ref{1:inc-1}] = deal(refstart{1:inc-1});
> refstatic(1:inc-1) = 0;
> end
> ...
>
> The condition ~(cellsize(1)==1) seems to cause the Bug. If I
> remove it from the test, as following:
>
> ...
> if (inc~=1)
> [ref{1:inc-1}] = deal(refstart{1:inc-1});
> refstatic(1:inc-1) = 0;
> end
> ...
>

Ditto, the test ~(cellsize(1)==1) is removed from the source
code of mat2cell in R2007b.

It seems to be a right fix for customer who still own older
version of MATLAB. I would expect Mathwork would react to my
question, but they seem to ignore it.

Bruno

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us