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:
"??? Error using ==> colon" in Matlab7 SP2

Subject: "??? Error using ==> colon" in Matlab7 SP2

From: Emiliano

Date: 27 May, 2005 09:08:51

Message: 1 of 9

Hi,
I recently installed Matlab 7 SP2 and I have a problem to report.

The following command line:
>xmesh=[xref: xdir*pixx: xref+xdir*pixx*(ndimx-1)];
generated the following error:
>??? Error using ==> colon
>Double operands interacting with integer operands must have integer
values.

This line of code did work with Matlab build 7.0.0.19920.

In this example:
xref=-255.5000
xdir*pixx=1
xref+xdir*pixx*(ndimx-1)=256

The strange thing is that when I execute the command (within a
debugger session in Matlab 7 SP2):
>xmesh=[-255.5000: 1: 256];
it works.

Perhaps someone @ Mathworks can figure out what's going on ...

Thanks !

Emiliano

Subject: "??? Error using ==> colon" in Matlab7 SP2

From: Bobby Cheng

Date: 27 May, 2005 15:27:10

Message: 2 of 9

What do

class(xdir*pixx)
class(xref+xdir*pixx*(ndimx-1))

give you?

One of these must be of integer class and xmesh will be of that integer
class.

Since [-255.5000: 1: 256] contains non-integer values, the resulting vector
may be be what you expect.

Try
xmesh=[xref: double(xdir*pixx): double(xref+xdir*pixx*(ndimx-1))];


"emiliano" <emiliano.spezi@physics.org> wrote in message
news:ef0749f.-1@webx.raydaftYaTP...
> Hi,
> I recently installed Matlab 7 SP2 and I have a problem to report.
>
> The following command line:
>>xmesh=[xref: xdir*pixx: xref+xdir*pixx*(ndimx-1)];
> generated the following error:
>>??? Error using ==> colon
>>Double operands interacting with integer operands must have integer
> values.
>
> This line of code did work with Matlab build 7.0.0.19920.
>
> In this example:
> xref=-255.5000
> xdir*pixx=1
> xref+xdir*pixx*(ndimx-1)=256
>
> The strange thing is that when I execute the command (within a
> debugger session in Matlab 7 SP2):
>>xmesh=[-255.5000: 1: 256];
> it works.
>
> Perhaps someone @ Mathworks can figure out what's going on ...
>
> Thanks !
>
> Emiliano

Subject: Re:

From: Emiliano

Date: 29 May, 2005 04:42:06

Message: 3 of 9

Hi Bobby,

the result is:

class(xdir*pixx)
class(xref+xdir*pixx*(ndimx-1))

ans =

double

ans =

uint16

ndimx is of class uint16!
The line code that you suggested works.

Matlab's coding is getting closer and closer to a proper programming
language. A bit fussy but it's OK. However it could be a sensible
approach to have all variables automatically converted to the same
class and display a warning rather than generating an error message
for a code that was working well with a previous release.

Thanks!

Emiliano

Bobby Cheng wrote:
>
>
> What do
>
> class(xdir*pixx)
> class(xref+xdir*pixx*(ndimx-1))
>
> give you?
>
> One of these must be of integer class and xmesh will be of that
> integer
> class.
>
> Since [-255.5000: 1: 256] contains non-integer values, the
> resulting vector
> may be be what you expect.
>
> Try
> xmesh=[xref: double(xdir*pixx): double(xref+xdir*pixx*(ndimx-1))];
>
>
> "emiliano" <emiliano.spezi@physics.org> wrote in message
> news:ef0749f.-1@webx.raydaftYaTP...
>> Hi,
>> I recently installed Matlab 7 SP2 and I have a problem to
report.
>>
>> The following command line:
>>>xmesh=[xref: xdir*pixx: xref+xdir*pixx*(ndimx-1)];
>> generated the following error:
>>>??? Error using ==> colon
>>>Double operands interacting with integer operands must have
> integer
>> values.
>>
>> This line of code did work with Matlab build 7.0.0.19920.
>>
>> In this example:
>> xref=-255.5000
>> xdir*pixx=1
>> xref+xdir*pixx*(ndimx-1)=256
>>
>> The strange thing is that when I execute the command (within a
>> debugger session in Matlab 7 SP2):
>>>xmesh=[-255.5000: 1: 256];
>> it works.
>>
>> Perhaps someone @ Mathworks can figure out what's going on ...
>>
>> Thanks !
>>
>> Emiliano
>
>
>

Subject: "??? Error using ==> colon" in Matlab7 SP2

From: Nadzri

Date: 11 Apr, 2013 13:30:08

Message: 4 of 9

I've also encounter the same problem. Shouldn't colon accept even the number is not an integer, I'm just starting to learn MATLAB. Your help is greatly appreciated

handles.value_n = str2double (get(hObject, 'string'));
n = handles.value_n;
a = handles.value_a;
b = handles.value_b;
handles.h =(b-a)/n;
h = handles.h;
handles.x=a:h:b
x=handles.x;
guidata (hObject, handles);

this is part of the code where I'm doing for trapezoid rule, where at the moment I've been trying with a=0, b = 1, and n = 10. I'm unable to obtain x due to h not being an integer.

Subject: "??? Error using ==> colon" in Matlab7 SP2

From: Steven_Lord

Date: 11 Apr, 2013 13:55:54

Message: 5 of 9



"Nadzri " <nadzri87@gmail.com> wrote in message
news:kk6dsv$9g$1@newscl01ah.mathworks.com...
> I've also encounter the same problem.

Since you responded to a nearly 8 year old post and didn't provide context,
I assume "the same problem" means this error message:

        Double operands interacting with integer operands must have integer
values.

> Shouldn't colon accept even the number is not an integer, I'm just
> starting to learn MATLAB. Your help is greatly appreciated

Yes, COLON can operate on noninteger values.

x1 = 0:0.25:1.5

However, "integer" is being used in two different senses in that error.
[I'll check with the developers to determine if we can improve the text of
the message to avoid that overloading.]

You cannot use COLON if at least one of the operands is of class double AND
at least one of the operands is of one of the eight integer classes (int8,
int16, int32, int64, uint8, uint16, uint32, uint64) AND at least one of the
operands of class double contains a value that is not an integer.

x2 = int8(0):1.5:int8(9) % Will NOT work

This is because the result should be of the integer class as demonstrated by
the example below, but 1.5 is not exactly representable in any of the
integer classes:

x3 = int8(0):1:int8(9)
class(x3)
x4 = int8(1.5) % converts and rounds

If you need an integer array containing the rounded values with a noninteger
valued step, use COLON on double precision values then convert to the
integer type.

x5 = int8(0:1.5:9)

> handles.value_n = str2double (get(hObject, 'string'));
> n = handles.value_n;
> a = handles.value_a;
> b = handles.value_b;
> handles.h =(b-a)/n;
> h = handles.h;
> handles.x=a:h:b
> x=handles.x;
> guidata (hObject, handles);
>
> this is part of the code where I'm doing for trapezoid rule, where at the
> moment I've been trying with a=0, b = 1, and n = 10. I'm unable to obtain
> x due to h not being an integer.

Be careful about the classes of a, b, and h. At least one of them, I'd
guess, is of an integer class.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: "??? Error using ==> colon" in Matlab7 SP2

From: dpb

Date: 11 Apr, 2013 14:06:47

Message: 6 of 9

On 4/11/2013 8:30 AM, Nadzri wrote:
> I've also encounter the same problem. Shouldn't colon accept even the
> number is not an integer, I'm just starting to learn MATLAB. Your help
> is greatly appreciated
>
> handles.value_n = str2double (get(hObject, 'string'));
> n = handles.value_n;
> a = handles.value_a;
> b = handles.value_b;
> handles.h =(b-a)/n;
> h = handles.h;
> handles.x=a:h:b
> x=handles.x;
> guidata (hObject, handles);
>
> this is part of the code where I'm doing for trapezoid rule, where at
> the moment I've been trying with a=0, b = 1, and n = 10. I'm unable to
> obtain x due to h not being an integer.

Unfortunately, only your response to a previous thread showed up on
usenet so can't see what the context was, but "yes, colon accepts
nonintegral delta", so the problem is something else.

W/o actual error can't say specifically what the problem might be but

 >> n = 5;
  a = 0.0;
  b = 1.0;
  handles.h =(b-a)/n;
  h = handles.h;
  handles.x=a:h:b
handles =
     h: 0.2000
     x: [0 0.2000 0.4000 0.6000 0.8000 1]
 >>

So, possibly this is a case of conflicting in names--mayhaps an
inadvertent 'colon' has been created as a variable or structure by a
previous typo--what does

which colon

produce at the command line? Or do symptoms disappear if do

clear colon

Otherwise cut 'n paste from an actual session what produces the problem
and the results showing it...

--

Subject: "??? Error using ==> colon" in Matlab7 SP2

From: anyone

Date: 11 Apr, 2013 17:17:07

Message: 7 of 9

On Thu, 11 Apr 2013 09:55:54 -0400, Steven_Lord wrote:

> "Nadzri " <nadzri87@gmail.com> wrote in message
> news:kk6dsv$9g$1@newscl01ah.mathworks.com...
>> I've also encounter the same problem.
>
> [...] a nearly 8 year old post

[snippage]

wow... now that was impressive, Steve.

Subject: "??? Error using ==> colon" in Matlab7 SP2

From: Steven_Lord

Date: 11 Apr, 2013 18:52:38

Message: 8 of 9



"anyone" <jaup@h/WSWLG{nR1qH_e> wrote in message
news:5166f013$0$58196$c3e8da3$88b277c5@news.astraweb.com...
> On Thu, 11 Apr 2013 09:55:54 -0400, Steven_Lord wrote:
>
>> "Nadzri " <nadzri87@gmail.com> wrote in message
>> news:kk6dsv$9g$1@newscl01ah.mathworks.com...
>>> I've also encounter the same problem.
>>
>> [...] a nearly 8 year old post
>
> [snippage]
>
> wow... now that was impressive, Steve.

Not really. While my newsreader software doesn't have the older posts (that
would consume a lot of space on my machine -- CSSM is fairly active) the
MATLAB Central newsreader does and at the time I responded this was pretty
close to the top entry on the page.

http://www.mathworks.com/matlabcentral/newsreader/view_thread/96674

May 2005 to April 2013 is close enough to 8 years to round up.

And I don't know if my assumption was correct, since Nadzri hasn't responded
yet to indicate that it was.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: "??? Error using ==> colon" in Matlab7 SP2

From: anyone

Date: 12 Apr, 2013 00:52:32

Message: 9 of 9

On Thu, 11 Apr 2013 14:52:38 -0400, Steven_Lord wrote:

> "anyone" <jaup@h/WSWLG{nR1³qH_e> wrote in message
> news:5166f013$0$58196$c3e8da3$88b277c5@news.astraweb.com...
>> On Thu, 11 Apr 2013 09:55:54 -0400, Steven_Lord wrote:
>>
>>> "Nadzri " <nadzri87@gmail.com> wrote in message
>>> news:kk6dsv$9g$1@newscl01ah.mathworks.com...
>>>> I've also encounter the same problem.
>>>
>>> [...] a nearly 8 year old post
>>
>> [snippage]
>>
>> wow... now that was impressive, Steve.
>
> Not really. While my newsreader software doesn't have the older posts
> (that would consume a lot of space on my machine -- CSSM is fairly
> active) the MATLAB Central newsreader does and at the time I responded
> this was pretty close to the top entry on the page.
>
> http://www.mathworks.com/matlabcentral/newsreader/view_thread/96674
>
> May 2005 to April 2013 is close enough to 8 years to round up.
>
> And I don't know if my assumption was correct, since Nadzri hasn't
> responded yet to indicate that it was.

Well, I liked it... '8 year old' in the hardware tech sector is, in a rough sense, two product cycles.

Tags for this Thread

No tags are associated with 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