检测边界/边缘 - MATLAB

时间:2015-03-04 17:15:50

标签: matlab

我使用randi生成随机数,然后从随机数中添加和减去一定数量:

for k=1:1000
     dist = poissrnd(RsMean,1,1);
     points(k,1) = randi([1, 1000]); 
     edges(k,1) = points(k,1)-dist;
     edges(k,2) = points(k,1)+dist;
end

当计算边缘时,我希望它考虑到值不能超出边界(在这种情况下为1-1000)。例如,目前,如果点包含值20和dist = 450,则边缘将记录-430和470.

我知道我可以这样做:

edges(edges<1) = 1;
edges(edges>1000) = 1000;

但是有没有更简洁的方法在MATLAB上进行边缘检查?

1 个答案:

答案 0 :(得分:0)

我不认为它更简洁,但你可以使用min和max:

% Take the minimum between edges and 1000
edges = min(edges, 1000)
% Take the maximum between edges and 1
edges = max(edges, 1)