• Register
1 vote

Problem :

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


     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);



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?

9 6 2
3,980 points

Please log in or register to answer this question.

2 Answers

1 vote

Solution :

I can help you in your Matlab related problem. Please note that your MATLAB was sending the above listed warning during your program running for your "LINE 1" and the cause of your above warning is because of the non integer values of your vector "mv_MV". So by using a round command for vector values will solve your problem. Please also note that a position of errors in the MATLAB pointing to should not be necessarily a very accurate position of your mistakes in your code which is causing the errors.

5 4 2
17,150 points
0 votes


  • IntegerOperandsRequired.m


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.


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.


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);

or better yet, only employ the padarray() function to do your padding.

10 6 4
31,120 points

Related questions

0 votes
1 answer 10 views
0 votes
1 answer 8 views
Problem: Comparison Operators are used to perform comparisons. Concatenation Operators are used to combine strings. Logical Operators are used to perform logical operations and include AND, OR, or NOT. Boolean Operators include AND, OR, XOR, or NOT and can have one of two values, true or false. What is the name of the operator when applied to strings?
asked Feb 22 Ali 5.7k points
0 votes
1 answer 291 views
Problem : I have very simple problem that currently looking for the fast implementation in Matlab. I have below array of values: b = floor(rand(5,5).*255) I also have the similarly sized threshold array : b_thresh = floor(rand(5,5).*255) I want to use the ... But, I am facing below error : Operands to || and && operations must be convertible to logical scalar values How can I resolve the issue?
asked Dec 21, 2019 alecxe 7.5k points
0 votes
2 answers 77 views
Problem: When C++ is working with an operator, it strives to convert the operands to the same type? True False
asked Apr 12, 2020 ArifulIslam 7.5k points
0 votes
1 answer 103 views
Problem: I have recently started learning matlab from the online tutorials. Currently I have the angle information as shown below for your reference: for i=1:10    angles = func1(val);    polar([angles 0]*pi/180,[15 0],'r'); end The angles is a 512x1 ... and because of lockdown no help is available so posting my question online. I need matlab expert who can help me in fixing my above error.
asked Aug 12, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 56 views
Problem: I am naïve to Matlab. Few days ago I had these four lines written in my file called mno.m function [x, y] = mno(q, r)     x=q;     y=r; end If I try to press CTRL+enter then I first get the popup that reads: The selected section cannot ... available on line on this error but that did not help me in fixing above error. Do you know some Matlab expert who can fix this error for me?
asked Jul 27, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 4 views
Problem: My code is this : d = unifrnd (0,10,[10,1]); c = d.^(-2); a = round(unifrnd(0,1,[1,10]); e = a*c btotal = e+1 SIR = 1/btotal What I want is to iterate this function 1000 times, each time the value of SIR will vary due to the ... generated. For every iteration, I want the value of SIR to be added together (summed up), and in the end of the 1000th iteration, find the average SIR(mean).
asked 6 days ago Ashty 1.7k points
0 votes
1 answer 16 views
Problem: iu must be specified for systems with more than one input.
asked Feb 18 charles mathews 3.8k points
0 votes
1 answer 14 views
Problem: I am trying to read a matlab file with the following code import scipy.io mat = scipy.io.loadmat('test.mat') and it gives me the following error raise NotImplementedError('Please use HDF reader for matlab v7.3 files') NotImplementedError: Please use HDF reader for matlab v7.3 files so could anyone please had the same problem and could please explain in detail
asked Feb 17 Mashhoodch 10.2k points
0 votes
1 answer 32 views
Problem: write two nested for loops to calculate the following double summation
asked Feb 12 Dan phillip 1.9k points