Something wrong with "floor" or "fix" functions or it's my code?
Afficher commentaires plus anciens
Hello,
row and col contain a lot of values of rows and cols. I'm trying to scale down the rows and cols to 1/4 sizes (rs,cs) and ps is the linear index in the scaled down matrix.
rs = fix((row-1)/4) + 1; %scale down of rows
cs = fix((col-1)/4) + 1; %scale down of cols
ps = (cs - 1)*140 + rs; %linear index in 140x140 matrix
It complains that the Index must not exceed 19600. I isolated the problem whenever the col = 559, the cs = 141 instead of 140. If I run the code individually on the command window >> cs = floor((559-1)/4) + 1; or >> cs = fix((559-1)/4) + 1; it gives me the correct value 140.
Anyone sees the problem that I can't see? I appreciate your help.
2 commentaires
Cris LaPierre
le 10 Mai 2023
If the error only appears when you pass in a vector, then you will likely need to share you data for us to see it. You can save your variables to a mat file and then attach that to your post.
DB
le 10 Mai 2023
Réponse acceptée
Plus de réponses (1)
I predict that your col was not calculated using pure integers, and instead was calculated by a process that divided by a number and later multiplied by the number. For example if you had (0:0.1:5) * 10 then you will not get back perfect integers:
x = 0:0.1:5;
x(x*10 ~= round(x*10))
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!