Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Algorithm 索引越界_Algorithm_Matlab - Fatal编程技术网

Algorithm 索引越界

Algorithm 索引越界,algorithm,matlab,Algorithm,Matlab,我必须将图像的RBG保存在3个不同的矢量中(每种颜色一个矢量)。然后,对于所有向量,我计算在[0;255]间隔中发现的每个像素的出现次数。我必须将[0;255](像素范围)间隔拆分为N个间隔,并使用以下公式计算每个间隔的总和: [x*256/N;x*256/N+256/N) 使用x可以得到“索引越界”,因为int16(256/N)中的四舍五入 有时结果会四舍五入到下一个较小的值,有时会四舍五入到下一个较大的值(即超出边界时) 解决方案:使用楼层(256/N) >而不是 256(n/n)< /代码

我必须将图像的RBG保存在3个不同的矢量中(每种颜色一个矢量)。然后,对于所有向量,我计算在[0;255]间隔中发现的每个像素的出现次数。我必须将[0;255](像素范围)间隔拆分为N个间隔,并使用以下公式计算每个间隔的总和:

[x*256/N;x*256/N+256/N)


使用x可以得到“索引越界”,因为
int16(256/N)
中的四舍五入

有时结果会四舍五入到下一个较小的值,有时会四舍五入到下一个较大的值(即超出边界时)


解决方案:使用<代码>楼层(256/N)<代码> >而不是<代码> 256(n/n)< /代码> .< /p>第一次查看,考虑使用<代码> SistC< <代码>或>代码>(零和int16是例外,因为它们不会使任务变得更简单)

N = 16 ... int16(256/N) = 16 (no rounding)
N = 19 ... int16(256/N) = 13 (13.47 is rounded to 13)
N = 20 ... int16(256/N) = 13 (12.80 is rounded to 13)