• Register
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?

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

Solution:

  • IntegerOperandsRequired.m

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

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

10 6 4
31,120 points

Related questions

0 votes
1 answer 6 views
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?
asked Mar 15 ummesalma 29.2k points
1 vote
1 answer 10 views
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.
asked Mar 26 PkGuy 23.5k points
0 votes
1 answer 12 views
0 votes
1 answer 3 views
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.
asked 2 days ago anika11 32k points
1 vote
1 answer 4 views
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?
asked Mar 29 PkGuy 23.5k points
0 votes
1 answer 7 views
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?
asked Apr 1 rakib1 51.5k points
0 votes
1 answer 4 views
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?
asked Mar 30 tuhin1 48.9k points
1 vote
1 answer 5 views
5 views
Problem: I am facing this problem on Mtlab please resolve it: Matlab operands to the and operators must be convertible.
asked Apr 27 PkGuy 23.5k points
0 votes
1 answer 3 views
3 views
Problem: whitePixels=ext_rows((150<ext_rows) && (ext_rows<200)); numberWhitePixels=numel(whitePixels); error : Operands to the || and && operators must be convertible to logical scalar values. How can I solve this error? Could you please write down the correct code here?
asked Apr 25 Moumita Bhowmick 12.4k points
0 votes
1 answer 5 views
5 views
Problem: I have a simple problem that I'm looking for fast implementation in Matlab. I have an array of values. I get an error that says: Operands to || and && operations must be convertible to logical scalar values
asked Apr 24 ummeshani 9k points