Explanation for : Warning: Integer operands are required for colon operator when used as index. > In welch>loca​lComputeSp​ectra (line 379)

8 views (last 30 days)
Vaibhav Kumar
Vaibhav Kumar on 12 Jan 2022
Answered: Walter Roberson on 12 Jan 2022
I am getting the following warning when I use mscohere() and tfestimate()
Warning: Integer operands are required for colon operator when used as index.
> In welch>localComputeSpectra (line 379)
In welch (line 170)
In tfestimate (line 151)
In BandwidthPhaseDelayCalculator (line 50)
In WingBorneFlightPathChirpsForPitchRateLOES_MatlabWrapper (line 131)
In WingBorneLOESDataExtractorLocalOnly (line 116)
The warning comes on for the following commands :
[CF,frq1] = mscohere(u, y, wind, No, NFFT, 1/dti);
[TF,frq2] = tfestimate(u, y, wind, No, NFFT, 1/dti);
I believe this error is due to the windowing and other parameters being sent to the functions, If I just use the u, y input arguments for arrays into both functions, I don't get this warning.
I want to understand the following:
  1. Why I am getting this warning?
  2. What does this warning actually mean?
  3. How is MATLAB handling this error with non integer operands.

Answers (1)

Walter Roberson
Walter Roberson on 12 Jan 2022
Your No variable corresponds to the overlap which is required to be a positive integer according to the documentation. However whatever you are passing in there is not an integer.
The internal code is doing
LminusOverlap = L-noverlap;
xStart = 1:LminusOverlap:k*LminusOverlap;
xEnd = xStart+L-1;
If your supplied an overlap that is not an integer, then LminusOverlap will not be an integer, and the 1:LminusOverlap:k*LminusOverlap will generate a sequence of values that are not all integers.
The code then later has
[Sxxk,w] = computeperiodogram({x(xStart(ii):xEnd(ii),:),...
so it tries to use the computed xStart values as indices into x but you have a problem using those values as indices when one of them is not an integer.
You can only overlap by a whole number of samples, not by a fraction of a sample.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!