我是靠谱客的博主 笑点低御姐,这篇文章主要介绍matlab随机抽取数字,从网格数据中随机抽样:如何在Matlab中实现这一点?,现在分享给大家,希望可以做个参考。

建立my answer to your simpler question,这里有一个解决方案,你可以选择15个随机整数点(即你的200乘200矩阵的下标索引),并分配从上面给出的值集中抽取的随机值:

mat = [...]; %# Your 200-by-200 matrix

x = [...]; %# Your 20 x coordinates given above

y = [...]; %# Your 20 y coordinates given above

data = [...]; %# Your 20 data values given above

fixedPoints = [x(:) y(:)]; %# Your 20 points in one 20-by-2 matrix

randomPoints = randi(200,[15 2]); %# A 15-by-2 matrix of random integers

isRepeated = ismember(randomPoints,fixedPoints,'rows'); %# Find repeated sets of

%# coordinates

while any(isRepeated)

randomPoints(isRepeated,:) = randi(200,[sum(isRepeated) 2]); %# Create new

%# coordinates

isRepeated(isRepeated) = ismember(randomPoints(isRepeated,:),...

fixedPoints,'rows'); %# Check the new

%# coordinates

end

newValueIndex = randi(20,[1 15]); %# Select 15 random indices into data

linearIndex = sub2ind([200 200],randomPoints(:,1),...

randomPoints(:,2)); %# Get a linear index into mat

mat(linearIndex) = data(newValueIndex); %# Update the 15 points在上面的代码中,我假设x坐标对应于行索引,而y坐标对应于列索引到mat。如果它实际上是相反的方式,则将第二个和第三个输入交换到函数SUB2IND。

最后

以上就是笑点低御姐最近收集整理的关于matlab随机抽取数字,从网格数据中随机抽样:如何在Matlab中实现这一点?的全部内容,更多相关matlab随机抽取数字内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(133)

评论列表共有 0 条评论

立即
投稿
返回
顶部