??? Error using ==> colon Colon operands must be in range of the data type.
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
HI,
I have a matrix of size "res<1*11969>". I would like to retrieve the values from index 900 to 11969 automatically. When I gave like this
mStart=900;
mEnd=11969;
res(:,[mStart:mEnd]) it shows an error " colon Colon operands must be in range of the data type" .
It will run if I gave res(:,[900:mEnd]).
But if I give res(:,[mStart:11969])it will shows the same error.
Kindly help in this issue as I would like to pass the values with variables.
Don
4 Kommentare
DGM
am 13 Nov. 2024
Bearbeitet: DGM
am 13 Nov. 2024
The error seems to be happening because the requested range of values does not lie within the range available to the inherited integer class.
This can happen if the arguments are a mix of float classes and (at most one) integer class. In this scenario, the output class (and the range of possible values) are inherited from the integer class present in the input arguments.
For example:
a = uint8(64); % one argument is uint8, so that's what the output must be
b = 512; % the other is double float
x = a:b % but 512 is not in the range of uint8 [0 255]
That said, I don't know how it would be possible to cause this error with arguments of 900 and 11000. Neither are within the range of 8b integer classes, and both are within the range of 16b integer classes. There is nothing in the given code which would imply that either are integer-class at all.
I can't think of a reason that could implicate the : used for the dim1 subscript.
Walter Roberson
am 13 Nov. 2024
If we suppose that
mStart = uint8(900)
mEnd=11969
then mStart:mEnd would be an error.
Of course 900 saturates uint8 and would be the value uint8(255) -- but it is not an error to saturate uint8, so perhaps it was not noticed that it was happening.
Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!