# Integer operands are required for colon operator when used as index.

1 vote
177 views

## Problem :

Recently I have joined a new project on Matlab. Please find below part of my Matlab code:

``````  rawmb=ceil(myCount/22);

i = rawmb*16-15;

j = colmb*16-15;

% dy is row(vertical) index

% dx is col(horizontal) index

dy = mv_MB(1);

dx = mv_MB(2);

refBlkVer = i + dy;

refBlkHor = j + dx;

myimageComp(i:i+15,j:j+15) = myimgI(refBlkVer:refBlkVer+15, refBlkHor:refBlkHor+15);``````

Where:

myCount is my integer number which is in the interval [1-396].

mv_MB is my 2*1 column vector.

myimgI is my matrix of the size [288, 352].

myimageComp is my matrix of the size [288, 352].

But whenever I try to run my above code I often receive the below warning:

``“Integer operands are required for colon operator when used as index.”``

Can some expert in Matlab help me in fixing above error?

1 vote

## Solution:

### Explanation:

You have employed a noninteger value as one of the parameters (starting value, increment, or stopping value) for the colon (:) operator at the time employing it to make a vector of indices to reference into a function.

### Reason:

You accomplished computations to gain the begining or stopping values for the indexing however the result of those computations was not accurately an integer.

To solve this problem:

Modify the index computations employing the FIX, FLOOR, CEIL, or ROUND functions to make sure that the indices are integers. You can examine in case a variable compprises an integer by comparing the variable to the output of the ROUND function operating on that variable at the time MATLAB is in debug mode on the line bearing the variable.

### This is caused by something like:

``````T = rand(1,10);
T(2.2:7.99)   % Note the indexing by:  2.2:7.99``````

Hence you require to look through your code and spot where you are employing a colon operator like the above. BTW, this fixes the warning message and produces the similar output.

``T(floor(2.2:7.99))``

### Do this at the command line:

``dbstop if warning``

Here, it must be noted that MATLAB was sending the above warning at the time of program runnig for the "LINE 1", while the reason of this warning was due to the non integer values of vector "mv_MV". So, employing the round command for its values solved the issue.

Now I have a great experience: "The position of errors MATLAB pointing to, is not constrainedly the exact position of mistakes in the code, causing the errors".

N1 is odd, so N1/2 is a fraction. Include 1 to that and it is still a fraction. You are then attempting to index from 1 to that fraction. That will provide you a warning.

You require to either prevent N1 from being odd, or otherwise you require to employ floor() or fix() or round() on the N1/2 so that it is no longer a fraction

(N-sizeData)/2 can be a fractional number, for example "something point 5" so attempt

``padding = floor((N-sizeData)/2);``

## Related questions

6 views
Problem: why do I receive ''Warning: Integer operands are required for colon operator when used as index" when running my program in matlab?
1 vote
10 views
Problem: How to create a row array like this? Construct a row array countvalues from 1 to endvalue, using the double colon operator.
12 views
I am finding difficulty with
3 views
Problem: I am dealing with a very huge matrix and so wanted to use parallel computing in MATLAB to run in clusters. Here I have created a sparse matrix using: Ad = sparse(length(con)*length(uni_core), length(con)*length(uni_core)); I have a written function adj ... any problem. But in parfor in parallel computing I am getting an error that there is a problem in using the sliced arrays with parfor.
1 vote
4 views
Problem: While drawing a UML when to use an attributive property instead of an associative composition? As association class is frequently required for what kind of relationship?
7 views
Problem: As I mentioned in my previous query, I'm having difficulties with my learning; I've tried searching the web but haven't been able to find adequate information; could you assist me in continuing my project?
4 views
Problem: As I mentioned in my previous query, I'm having difficulties with my learning; I've tried searching the web but haven't been able to find adequate information; could you assist me in continuing my project?
1 vote