Got Questions? Get Answers.
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:
Baffling colon behaviour

Subject: Baffling colon behaviour

From: David Young

Date: 30 Mar, 2010 00:23:02

Message: 1 of 6

I am puzzled by the following (observed in 2009a 64 bit Linux and 2010a 64 bit Windows):

>> [a, b, c] = deal(1, :, 2);
>> strcmp(b, ':')

ans =

     1

I can't fit this into any of my mental schema relating to how things should work, or find any documentation that would explain it. I feel I must be missing something (quite possible at 1 am, as it is here) - can anyone shed any light please?

I can't find a bugreport, but I'm beginning to wonder if I've found a bug.

(For anyone who doesn't see the problem: deal is a function, not an array. You'd expect a naked colon to be meaningless as an argument, and for the first line of my example to cause an error. To get a string back is very strange.)

Subject: Baffling colon behaviour

From: Matt Fig

Date: 30 Mar, 2010 00:51:05

Message: 2 of 6

Using 2007b:

>> [a, b, c] = deal(1, :, 2);
??? At compilation, "deal" was determined to be a variable and this
 variable is uninitialized. "deal" is also a function name and previous versions of MATLAB would have called the function.
 However, MATLAB 7 forbids the use of the same name in the same
 context as both a function and a variable.

What does:
>>which deal
say?

Subject: Baffling colon behaviour

From: David Young

Date: 30 Mar, 2010 00:59:08

Message: 3 of 6

"Matt Fig" <spamanon@yahoo.com> wrote in message <horhtp$q5e$1@fred.mathworks.com>...
> What does:
> >>which deal
> say?

>> which deal
C:\Program Files\MATLAB\R2010a\toolbox\matlab\datatypes\deal.m

Subject: Baffling colon behaviour

From: David Young

Date: 30 Mar, 2010 01:07:06

Message: 4 of 6

Matt: thanks, that's given me something to think about. In 2010a the behaviour you see is preserved (with a shorter message) if there are only 2 arguments to deal:

>> [a, b] = deal(1,:)
??? Undefined variable deal.

I can understand this: if there's a naked colon, then deal must be a variable not a function, it's not defined, so error.

It's looking increasingly as if there is a bug for more than 2 arguments: the function is being called, and a representation of the lexical token is being passed to it without any attempt at evaluation.

Subject: Baffling colon behaviour

From: Matt Fig

Date: 30 Mar, 2010 01:29:07

Message: 5 of 6

Did they change DEAL.m? Is it still just basically:

varargout = varargin;

or what?

Subject: Baffling colon behaviour

From: David Young

Date: 30 Mar, 2010 06:30:08

Message: 6 of 6

"Matt Fig" <spamanon@yahoo.com> wrote in message <hork53$pjn$1@fred.mathworks.com>...
> Did they change DEAL.m? Is it still just basically:
>
> varargout = varargin;
>
> or what?

It's not a problem with deal - I was just using deal to demonstrate the problem. It's any case where a naked colon appears as one of three arguments to a function.

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