Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Integer operands are required for colon operator when used as index

879 views
Skip to first unread message

noam fisher

unread,
Oct 20, 2009, 9:35:03 AM10/20/09
to
Appears to me this error message:

Warning: Integer operands are required for colon operator when used as index

What does it mean? What should I do?

thanks

dpb

unread,
Oct 20, 2009, 9:35:16 AM10/20/09
to

A) Means can't have _non_-integer subscripts for arrays.

B) Use an integer or round the float to an integer...

Perhaps show your work???

--


John D'Errico

unread,
Oct 20, 2009, 9:52:02 AM10/20/09
to
"noam fisher" <noa...@walla.com> wrote in message <hbkea7$9hs$1...@fred.mathworks.com>...

Which element of an array or vector is element 3.276?

John

Feng Shan

unread,
Oct 29, 2009, 11:18:09 AM10/29/09
to

I also want to kown...

Steven Lord

unread,
Oct 29, 2009, 11:51:00 AM10/29/09
to

"Feng Shan" <fengs...@gmail.com> wrote in message
news:2c664323-98a6-4d25...@j9g2000prh.googlegroups.com...

When you index into a variable:

x = 1:10;

with an expression involving a colon:

x(1:5)

the elements generated by that colon operator should contain only integer
values; if it doesn't, you will receive that warning. For example:

x(1.5:1:5.5)

since 1.5:1:5.5 => [1.5 2.5 3.5 4.5 5.5] and none of those are integer
values, you will receive this warning.

--
Steve Lord
sl...@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ


Jeffery R

unread,
Dec 29, 2009, 4:17:05 PM12/29/09
to
Concerning the same error, with integer operands for colon operators, I am trying to do a bit of image processing. Though I am surely not going about it the most efficient way, I was trying to use ginput to reduce the size of an image. I have the following code, which results in the integer operand issue:

[x,y] = ginput(2)
size(Pic)
A = Pic(y(1):y(2),x(1):x(2),:);

Ab=A(:,:,3);

I am trying to take an image, convert it to RGB, display it, click an important area, make a new 3d matrix with the selected part of the image, zoom in, and then take only the blue layer and view it, and perform some calculations on the matrix as well. The g-input results are not integers, but I am not entirely sure what I should change about this. Also, currently my function is working, it just gives me this warning.

Thanks in advance.
-Jeff

Andy

unread,
Dec 29, 2009, 4:31:06 PM12/29/09
to
"Jeffery R" <jar...@cornell.edu> wrote in message <hhdrkh$6ao$1...@fred.mathworks.com>...

The function ginput returns x and y coordinate values, which are unlikely to be integers. So the line A = Pic(y(1):y(2),x(1):x(2),:); is generating this error.

On a separate note, the line size(Pic) does nothing if you don't store that data somewhere, e.g. [m,n]=size(Pic).

0 new messages